3) it also pisses off everyone you work with except for 3 people from the 70s who care about that stuff, or that creepy guy who talks about how his palm pilot is amazing because he can develop in C, man.
If you're interested in writing efficient code, macros are essential. If you don't care how efficient your code is, why are you writing it in C?
It's ternary not trinary, huh? I kinda feel like an idiot. Mister fancy pants education and as it turns out I don't actually know what to call that. X__X
mspencer on
MEMBER OF THE PARANOIA GM GUILD
XBL Michael Spencer || Wii 6007 6812 1605 7315 || PSN MichaelSpencerJr || Steam Michael_Spencer || Ham NOØK QRZ || My last known GPS coordinates: FindU or APRS.fi (Car antenna feed line busted -- no ham radio for me X__X )
what brand of sentient species would dare nest a ternary
they must be dealt with
The same kind of coder who just confuses newbie programmers by trying to teach them right off the bat the difference between a statement's expression value and a statement's side effects. Also that
3;
is a valid statement in C.
X__X
mspencer on
MEMBER OF THE PARANOIA GM GUILD
XBL Michael Spencer || Wii 6007 6812 1605 7315 || PSN MichaelSpencerJr || Steam Michael_Spencer || Ham NOØK QRZ || My last known GPS coordinates: FindU or APRS.fi (Car antenna feed line busted -- no ham radio for me X__X )
Hey guys, I managed to get myself a year's worth of Microsoft VPS hosting for free. I've actually managed to get most of the IIS 7 kibbles and bits working property. Now, my main concern is security. I'm a newbie at setting up a server anyway, and my only previous experience was getting an Ubuntu LAMP server up and running, so working on this is a bit daunting.
What I've done so far:
Got my domain's A records pointing in the right direction and the site bindings to work.
Installed .NET 4.0 and ASP.NET MVC 2.0
Installed SQL Server 2008 R2 (I created a separate user for the db itself, but use my admin acount as the db administrator user... dunno if it's the right way to go).
Created space for multiple domains on the HDD. Their wwwroot folders have default permissions - read and execute.
Installed FTP and created a separate user for that to keep it separate from the admin acount. Been having some trouble with testing it with Filezilla, but have been working with the hosting company's tech support on that.
So, with all that done, what can I do to make this thing as bulletproof as possible? Any good tuts on the subject?
Nightslyr on
PSN/XBL/Nintendo/Origin/Steam: Nightslyr 3DS: 1607-1682-2948 Switch: SW-3515-0057-3813 FF XIV: Q'vehn Tia
what brand of sentient species would dare nest a ternary
they must be dealt with
The same kind of coder who just confuses newbie programmers by trying to teach them right off the bat the difference between a statement's expression value and a statement's side effects. Also that
3;
is a valid statement in C.
X__X
Hmm? I had assumed that every statement had to include some sort of function, but now that I think about it statements can resolve to non-void values if you choose not to handle the output of a function. I suppose that in that case, the result of the evaluation would just be discarded. I do wonder how exactly it maps to machine code, though.
well, an optimizing compiler would remove that statement, since its value is not used and it has no side effects.
A non-optimizing compiler would put the value of the statement (3) into a return register, but nothing would pick it up, and it would get overwritten by the next returned value. (More or less.)
3) it also pisses off everyone you work with except for 3 people from the 70s who care about that stuff, or that creepy guy who talks about how his palm pilot is amazing because he can develop in C, man.
If you're interested in writing efficient code, macros are essential. If you don't care how efficient your code is, why are you writing it in C?
8-) I use VB.
No I don't.
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
Anyway, for those who hate macros, I pose a question to you: how would you do this without macros and maintaining both the execution speed and the simplicity?
The compiler is probably doing some inline magic on the macro that it can't do with virtual classes. But probably the problem exists completely because of dynamic_cast.
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
0
KakodaimonosCode fondlerHelping the 1% get richerRegistered Userregular
Anyway, for those who hate macros, I pose a question to you: how would you do this without macros and maintaining both the execution speed and the simplicity?
The compiler is probably doing some inline magic on the macro that it can't do with virtual classes. But probably the problem exists completely because of dynamic_cast.
It's a cute little toy program, but it's ant-fucking. Those perf numbers are for a million casts. If I'm doing a million dynamic casts in a program, I'm doing something wrong. And I'd bet my ass that any performance issues you see in a C++ project ain't going to be from how slow dynamic_cast is.
Anyway, for those who hate macros, I pose a question to you: how would you do this without macros and maintaining both the execution speed and the simplicity?
The compiler is probably doing some inline magic on the macro that it can't do with virtual classes. But probably the problem exists completely because of dynamic_cast.
Well yeah, casting to an arbitrary base class from a derived class is a trivial operation, so while dynamic_cast<> has to actually traverse the whole type tree both up and down, for the cost of a virtual call I automatically go to the most derived class and then check against every base class; the compiler sees a bunch of static calls and inlines everything.
As for why, it's really quite simple. I'm doing a Lua binding, allowing fairly easy access to C++ classes from inside Lua (and allowing Lua to implement C++ classes and letting C++ code call them directly). On every call you need to verify that the object you get passed is the correct type. Normally, you'd do a Lua lookup on the metatable of the object and check that it matches the one you expect, but this is much faster than a Lua table lookup
Scripting languages are already slow enough without having overhead on the C side of the call. The dynamic_cast<> thing is really just a nice bonus
it's also possible that the optimization is completely removing the dynamic cast altogether, since the result is never really used for anything. This might not reflect reality.
it's also possible that the optimization is completely removing the dynamic cast altogether, since the result is never really used for anything. This might not reflect reality.
The virtual function calls prevent that. I've also traced the asm and it does in fact do the casting
Lua's pretty nice, although it's a very different type of programming than I'm used to, so I'm not all that good with it yet.
The C API is pretty decent, it does require a lot of function calls to get stuff done, but you can get around that with a whole bunch of helper templates, to the point where you can almost call a Lua function just like a normal C one and all the stack manipulation that you need to do gets generated behind the scenes. The only thing that really seems to be completely missing is a way to easily integrate C++ classes with Lua objects
what brand of sentient species would dare nest a ternary
they must be dealt with
No ternary statement ever starts nested, but like a fungus they subdivide and grow over time.
Indeed. I'm currently looking at like a quintuple-nested ternary expression that's like 10 lines long that handles the generation of a pop-up menu in a JSP file, which I'd post if the code weren't proprietary. Every time I have to debug this POS I feel like getting violent.
MEMBER OF THE PARANOIA GM GUILD
XBL Michael Spencer || Wii 6007 6812 1605 7315 || PSN MichaelSpencerJr || Steam Michael_Spencer || Ham NOØK QRZ || My last known GPS coordinates: FindU or APRS.fi (Car antenna feed line busted -- no ham radio for me X__X )
People who use ternary statements like that just like to feel awesome about themselves. Fuck, just do an if/else statement you geese. Yeah I can understand what it did but if I ever come across a quintuple-nested statement like that, you'll be kicked in the shins and I'll tell you to rewrite it.
bowen on
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
0
GnomeTankWhat the what?Portland, OregonRegistered Userregular
edited July 2010
I use dynamic_cast quite extensively in my game engine, and the last time I did an optimization pass, I can promise you that dynamic_cast was never an issue. If you're dynamic_casting a million objects, perhaps you need to think of a better approach to your design.
Well, I'm not going to belabor the point, it was really just an example of one of the useful things with macros - autogenerating simple boilerplate code easily. I don't expect anyone to actually use it.
As for the actual code, I use it for two reasons: it's faster than both dynamic_cast and luaL_checkudata (and handles inheritance much better than luaL_checkudata as well), and since it has no dependencies on the RTTI system it can be used in environments where you can use C++ but can't use RTTI.
Well, I'm not going to belabor the point, it was really just an example of one of the useful things with macros - autogenerating simple boilerplate code easily. I don't expect anyone to actually use it.
I'll have to second this - macros are nice, but can be easily abused. I don't think anyone disagrees.
As for the actual code, I use it for two reasons: it's faster than both dynamic_cast and luaL_checkudata (and handles inheritance much better than luaL_checkudata as well), and since it has no dependencies on the RTTI system it can be used in environments where you can use C++ but can't use RTTI.
And where the objects you're casting are guaranteed to never be created in a (different) dynamic library.
For example:
Downcastable *DLLCreateTestObject(void)
{
return new foo;
}
is in a DLL which can be either linked directly to the executable, or dynamically loaded.
This is because you're relying on static pointers embedded into each class, and those static pointers are not going to be unique for the same class when dynamic libraries are involved.
This is part of the reason why dynamic_cast is so slow - it has to deal with these cases, and I believe that it uses string comparisons with the class names to make sure it works.
It would be hilarious to see a benchmark to see if short class names have faster dynamic_cast times than longer class names!
Edit:
Actually, an interesting workaround might be to just set those static functions as export functions from the DLL. Hmmm...
GnomeTankWhat the what?Portland, OregonRegistered Userregular
edited July 2010
I can't think of many C++ environments I care to compile in that don't support RTTI, but I'll concede some still exist (and I will certainly concede that many have terrible RTTI implementations with serious performance implications, though the latest GCC and VC++ compilers are pretty damn spanky when it comes to RTTI).
Not sure about luaL_checkuserdata, I use LuaBind for all of my Lua/C++ glue in the game engine.
Ah, good point. Dynamic linking will screw it up, whenever I have an library internally I'll set it up for static linking as I find extra dlls sitting around annoying, so I never really considered it.
Still, you could change the "p == UNIQUE_CLASS_ID(classname)" to "!strcmp((const char*)p, UNIQUE_CLASS_ID(classname))" and redefine UNIQUE_CLASS_ID(classname) to "classname::StaticGetClassName()". It loses a lot of the speed advantage (1.26 vs 0.45) unfortunately due to the more expensive compares though.
Of course, you could just assign a unique ID manually to each class, another param on the macro I suppose. It's just that having it happen automagically is nice
Pure virtuals with bodies are allowed. Subclasses still must define them but you can call the implementation in the parent. Since I always call the parent implementation I need one there. It doesn't have to be pure virtual but it's helpful if I forget to put the macros in, generates a compile error
The GCC error is because it doesn't allow a function pointer to autocast to void. I was using something else before which did, but changed it recently and haven't rechecked GCC since
I can't think of many C++ environments I care to compile in that don't support RTTI, but I'll concede some still exist (and I will certainly concede that many have terrible RTTI implementations with serious performance implications, though the latest GCC and VC++ compilers are pretty damn spanky when it comes to RTTI).
Not sure about luaL_checkuserdata, I use LuaBind for all of my Lua/C++ glue in the game engine.
It's incredibly niche, but I play around with OS development in C++ every now and then. No RTTI, no exceptions (unless you do a bunch of support work at least)
LuaBind looks pretty nice, however it looks like the per-state setup is rather expensive and can it handle Lua holding references/handling an early destroyed C object?
All the C# wrappers thus far are incomplete, no longer updated and I think its a good way to learn opengl. I think starting with 1.0 (I believe 1.0 doesnt support hardware rendering) would at least give me a good place to start.
Java has an up to date opengl wrapper in LWJGL (seriously, it updated yesterday). It's what I've used to go through the NeHe tutorials, which about everyone recommends besides the Red & Orange book as a starting point. You can even make 3d accelerated web applets with it, it's what Minecraft runs on.
If you really want to future proof yourself though, you should look into OpenGL ES. Almost all modern mobile phone games use it for graphics. The WebGL initiative to bring OpenGL to browsers is based on OpenGL ES 2.0.
All the C# wrappers thus far are incomplete, no longer updated and I think its a good way to learn opengl. I think starting with 1.0 (I believe 1.0 doesnt support hardware rendering) would at least give me a good place to start.
Java has an up to date opengl wrapper in LWJGL (seriously, it updated yesterday). It's what I've used to go through the NeHe tutorials, which about everyone recommends besides the Red & Orange book as a starting point. You can even make 3d accelerated web applets with it, it's what Minecraft runs on.
If you really want to future proof yourself though, you should look into OpenGL ES. Almost all modern mobile phone games use it for graphics. The WebGL initiative to bring OpenGL to browsers is based on OpenGL ES 2.0.
I just tried LWJGL and it thus far doesn't work. I tried http://lwjgl.org/wiki/doku.php/lwjgl/tutorials/opengl/basicopengl and it won't compile. I made sure to have their libraries hooked to the project and I get an error stating Could not initialize class org.lwjgl.opengl.Display.
You probably forgot to tell it to include the native libraries as well. You need to add a VM option for that when you're executing the program. Add
-Djava.library.path=native\windows
'native\windows' being the relative path to the directory with the appropriate libraries for your system. For eclipse, you need to add that to VM arguments under the Arguments tab of your program's Run configuration. If you're running from the command line, you just need to add that before the name of your main class.
You probably forgot to tell it to include the native libraries as well. You need to add a VM option for that when you're executing the program. Add
-Djava.library.path=native\windows
'native\windows' being the relative path to the directory with the appropriate libraries for your system. For eclipse, you need to add that to VM arguments under the Arguments tab of your program's Run configuration. If you're running from the command line, you just need to add that before the name of your main class.
It's there. I followed all the steps in the installation guide. I use NetBeans 6.9.
Can anyone remember this particular programming website? It was a series of increasingly difficult queries that you could write algorithms to answer in any language you wanted. Most of them were Maths based. You had to register to go through the programme. I thought it was pretty well known, but can't find it now.
Æthelred on
pokes: 1505 8032 8399
0
GnomeTankWhat the what?Portland, OregonRegistered Userregular
Oh my god, I've just discovered the purpose of LINQ while using WatiN.
This is beautiful
I use LINQ all over the place now, but mostly LINQ to Objects. If I have to write a really chunky list search, for instance, I'll write it as a LINQ query.
Can anyone remember this particular programming website? It was a series of increasingly difficult queries that you could write algorithms to answer in any language you wanted. Most of them were Maths based. You had to register to go through the programme. I thought it was pretty well known, but can't find it now.
Can anyone remember this particular programming website? It was a series of increasingly difficult queries that you could write algorithms to answer in any language you wanted. Most of them were Maths based. You had to register to go through the programme. I thought it was pretty well known, but can't find it now.
I'm going for a job interview at a company whose MO it is to use little programming tests like that. Thought I'd roll through 40 or so beforehand and the same one will probably come up. :P
Posts
they must be dealt with
If you're interested in writing efficient code, macros are essential. If you don't care how efficient your code is, why are you writing it in C?
XBL Michael Spencer || Wii 6007 6812 1605 7315 || PSN MichaelSpencerJr || Steam Michael_Spencer || Ham NOØK
QRZ || My last known GPS coordinates: FindU or APRS.fi (Car antenna feed line busted -- no ham radio for me X__X )
3;
is a valid statement in C.
X__X
XBL Michael Spencer || Wii 6007 6812 1605 7315 || PSN MichaelSpencerJr || Steam Michael_Spencer || Ham NOØK
QRZ || My last known GPS coordinates: FindU or APRS.fi (Car antenna feed line busted -- no ham radio for me X__X )
What I've done so far:
Got my domain's A records pointing in the right direction and the site bindings to work.
Installed .NET 4.0 and ASP.NET MVC 2.0
Installed SQL Server 2008 R2 (I created a separate user for the db itself, but use my admin acount as the db administrator user... dunno if it's the right way to go).
Created space for multiple domains on the HDD. Their wwwroot folders have default permissions - read and execute.
Installed FTP and created a separate user for that to keep it separate from the admin acount. Been having some trouble with testing it with Filezilla, but have been working with the hosting company's tech support on that.
So, with all that done, what can I do to make this thing as bulletproof as possible? Any good tuts on the subject?
Switch: SW-3515-0057-3813 FF XIV: Q'vehn Tia
Hmm? I had assumed that every statement had to include some sort of function, but now that I think about it statements can resolve to non-void values if you choose not to handle the output of a function. I suppose that in that case, the result of the evaluation would just be discarded. I do wonder how exactly it maps to machine code, though.
A non-optimizing compiler would put the value of the statement (3) into a return register, but nothing would pick it up, and it would get overwritten by the next returned value. (More or less.)
Pfft
You do it all the time when describing combinational logic in Verilog.
assign value = test1 ? value1 : test2 ? value2 : test3 ? value3 : value4;That's surprisingly easy to read, and a lot more compact than the alternative.
No ternary statement ever starts nested, but like a fungus they subdivide and grow over time.
I made a game, it has penguins in it. It's pay what you like on Gumroad.
Currently Ebaying Nothing at all but I might do in the future.
8-) I use VB.
dynamic_cast<T*>: 2.099350
T::TryCast: 1.636923
After optimized, though,
dynamic_cast<T*>: 1.915703
T::TryCast: 0.050271
The compiler is probably doing some inline magic on the macro that it can't do with virtual classes. But probably the problem exists completely because of dynamic_cast.
It's a cute little toy program, but it's ant-fucking. Those perf numbers are for a million casts. If I'm doing a million dynamic casts in a program, I'm doing something wrong. And I'd bet my ass that any performance issues you see in a C++ project ain't going to be from how slow dynamic_cast is.
Well yeah, casting to an arbitrary base class from a derived class is a trivial operation, so while dynamic_cast<> has to actually traverse the whole type tree both up and down, for the cost of a virtual call I automatically go to the most derived class and then check against every base class; the compiler sees a bunch of static calls and inlines everything.
As for why, it's really quite simple. I'm doing a Lua binding, allowing fairly easy access to C++ classes from inside Lua (and allowing Lua to implement C++ classes and letting C++ code call them directly). On every call you need to verify that the object you get passed is the correct type. Normally, you'd do a Lua lookup on the metatable of the object and check that it matches the one you expect, but this is much faster than a Lua table lookup
Scripting languages are already slow enough without having overhead on the C side of the call. The dynamic_cast<> thing is really just a nice bonus
The virtual function calls prevent that. I've also traced the asm and it does in fact do the casting
The C API is pretty decent, it does require a lot of function calls to get stuff done, but you can get around that with a whole bunch of helper templates, to the point where you can almost call a Lua function just like a normal C one and all the stack manipulation that you need to do gets generated behind the scenes. The only thing that really seems to be completely missing is a way to easily integrate C++ classes with Lua objects
Indeed. I'm currently looking at like a quintuple-nested ternary expression that's like 10 lines long that handles the generation of a pop-up menu in a JSP file, which I'd post if the code weren't proprietary. Every time I have to debug this POS I feel like getting violent.
XBL Michael Spencer || Wii 6007 6812 1605 7315 || PSN MichaelSpencerJr || Steam Michael_Spencer || Ham NOØK
QRZ || My last known GPS coordinates: FindU or APRS.fi (Car antenna feed line busted -- no ham radio for me X__X )
As for the actual code, I use it for two reasons: it's faster than both dynamic_cast and luaL_checkudata (and handles inheritance much better than luaL_checkudata as well), and since it has no dependencies on the RTTI system it can be used in environments where you can use C++ but can't use RTTI.
I'll have to second this - macros are nice, but can be easily abused. I don't think anyone disagrees.
And where the objects you're casting are guaranteed to never be created in a (different) dynamic library.
For example:
Downcastable *DLLCreateTestObject(void) { return new foo; }is in a DLL which can be either linked directly to the executable, or dynamically loaded.
This is executed in the executable itself:
will produce unexpected behaviour.
This is because you're relying on static pointers embedded into each class, and those static pointers are not going to be unique for the same class when dynamic libraries are involved.
This is part of the reason why dynamic_cast is so slow - it has to deal with these cases, and I believe that it uses string comparisons with the class names to make sure it works.
It would be hilarious to see a benchmark to see if short class names have faster dynamic_cast times than longer class names!
Edit:
Actually, an interesting workaround might be to just set those static functions as export functions from the DLL. Hmmm...
Edit2:
Actually, wouldn't work. Dependency problems.
Also, typo in the code you posted:
virtual void* TryCastTo(const void *p) = 0 { return NULL; };Pure virtual function... with a body? Since everything goes back to Downcastable, you probably want to remove the = 0.
Also, gcc complains about:
obj->TryCastTo(UNIQUE_CLASS_ID(classname))
Workaround:
obj->TryCastTo((void*)UNIQUE_CLASS_ID(classname))
WHOO! C style casting! Because I'm too lazy to suggest a proper fix!
Not sure about luaL_checkuserdata, I use LuaBind for all of my Lua/C++ glue in the game engine.
Still, you could change the "p == UNIQUE_CLASS_ID(classname)" to "!strcmp((const char*)p, UNIQUE_CLASS_ID(classname))" and redefine UNIQUE_CLASS_ID(classname) to "classname::StaticGetClassName()". It loses a lot of the speed advantage (1.26 vs 0.45) unfortunately due to the more expensive compares though.
Of course, you could just assign a unique ID manually to each class, another param on the macro I suppose. It's just that having it happen automagically is nice
Pure virtuals with bodies are allowed. Subclasses still must define them but you can call the implementation in the parent. Since I always call the parent implementation I need one there. It doesn't have to be pure virtual but it's helpful if I forget to put the macros in, generates a compile error
The GCC error is because it doesn't allow a function pointer to autocast to void. I was using something else before which did, but changed it recently and haven't rechecked GCC since
It's incredibly niche, but I play around with OS development in C++ every now and then. No RTTI, no exceptions (unless you do a bunch of support work at least)
LuaBind looks pretty nice, however it looks like the per-state setup is rather expensive and can it handle Lua holding references/handling an early destroyed C object?
Java has an up to date opengl wrapper in LWJGL (seriously, it updated yesterday). It's what I've used to go through the NeHe tutorials, which about everyone recommends besides the Red & Orange book as a starting point. You can even make 3d accelerated web applets with it, it's what Minecraft runs on.
If you really want to future proof yourself though, you should look into OpenGL ES. Almost all modern mobile phone games use it for graphics. The WebGL initiative to bring OpenGL to browsers is based on OpenGL ES 2.0.
I just tried LWJGL and it thus far doesn't work. I tried http://lwjgl.org/wiki/doku.php/lwjgl/tutorials/opengl/basicopengl and it won't compile. I made sure to have their libraries hooked to the project and I get an error stating Could not initialize class org.lwjgl.opengl.Display.
I am unimpressed.
It's there. I followed all the steps in the installation guide. I use NetBeans 6.9.
With
Well there is your problem. You need the 'lwjgl\native\windows' directory for the native libraries, not the jar directory.
This is beautiful
can't get the f'ing classesDir thing to work
apply plugin: 'java' classesDir = new File('target/classes')the documentation is difficult to read I guess, at least different from what I"m used to. I can't get this to work.
B.net: Kusanku
I use LINQ all over the place now, but mostly LINQ to Objects. If I have to write a really chunky list search, for instance, I'll write it as a LINQ query.
Project Euler
The power of Christ blesses you.
I'm going for a job interview at a company whose MO it is to use little programming tests like that. Thought I'd roll through 40 or so beforehand and the same one will probably come up. :P