Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 09 Dec 1999
Offline Last Active Today, 10:40 AM

#5166901 Win32 BOOL and bool ?

Posted by SiCrane on 14 July 2014 - 09:32 PM

Note that sometimes the use of BOOL in the Windows API is a lie and is not actually a boolean. For the GetMessage() function, 0 indicates WM_QUIT, non-zero indicates a non-WM_QUIT message except for -1 which means an error. 

#5165733 c++ function pointers

Posted by SiCrane on 08 July 2014 - 11:32 PM

The easiest way is to use a typedef. Ex:  typedef int (*function_type)(int). Then function_type GiveMeFunctionPointer()

#5154357 c++ class vs struct+functions

Posted by SiCrane on 17 May 2014 - 08:52 PM

Assuming the member functions are non-virtual they'll compile into essentially identical machine code as functions that accept structs as pointer or reference arguments.

#5148473 C++ std::move() vs std::memcpy()

Posted by SiCrane on 20 April 2014 - 09:22 PM

One situation where memcpy() won't work but std::move() will is when the object's constructors and destructor handle self-registration. For example, if it registers itself as part of the root set to a garbage collector by giving the garbage collector it's address. If you just copy the the memory without updating the root set for the GC, the GC will be trying to use the old memory location for its sweeps.

#5147379 c++ oo syntax behind the scenes behavior

Posted by SiCrane on 16 April 2014 - 10:28 AM


where is the VMT stored, and when ?

With the memory of the class, when the class is created - usually alongside the member variables in memory.

I think you're confusing a pointer to the vtable and the vtable itself. An object will store a pointer to the vtable not the full table. The vtables themselves are generally stored in a read only data segment. 

#5146762 Error from/with unique_ptr trying to acces private member, error C2248

Posted by SiCrane on 13 April 2014 - 02:28 PM

A unique_ptr is movable but not copyable, which means a std::vector of unique_ptrs is also not copyable. And a class that contains a std::vector of unique_ptrs would also not be copyable with the default copy constructor or assignment operator. One option in your case is to give your Bag a copy constructor that clones all the pointed to Items. Another option is to use shared_ptrs instead of unique_ptrs.

#5146175 What does the standard say about this?

Posted by SiCrane on 11 April 2014 - 01:07 AM

According to the standard, "The full expressions in an initializer-clause are evaluated in the order which they appear." Section 8.5.1 paragraph 17 of C++11. Also, the elements of std::array<> constructed without an initializer are default initialized. In the case of a std::array of primitives this means no initialization is performed.

#5143724 Deleting pointers to inherited objects

Posted by SiCrane on 01 April 2014 - 10:22 AM

Deleting a derived object through a pointer to the base when there is no virtual destructor in the base class is undefined behavior. This means anything can happen including memory being freed properly. In practice what often happens is that the base class destructor is called and then a pointer allocated memory is passed to a deallocation function. Since most deallocation functions only accept a pointer without needing you to know how much memory was originally allocated, the memory of the class itself will be freed properly. However if the derived class contains objects that dynamically allocate memory (ex: a std::string object if small string opt didn't kick in) if the destructors for those objects are not called there will be a memory leak. Of course, this is only a common case. There are other possibilities, many of which will involve corrupting the heap.

#5141491 Management of game objects

Posted by SiCrane on 23 March 2014 - 12:38 PM

If you're using pointers, there isn't anything that stops you from having both a master Entity * container and separate containers for specific types. You can iterate over the master list when you want to batch process everything and over the type containers when you just want projectiles or enemies.

#5140343 What is the best 3D game to make first?

Posted by SiCrane on 19 March 2014 - 10:22 AM

A good beginning game is a Rubik's cube simulator. It's you, 36 polygons and no way out without actually understanding rotations. (Which sounds like it would be the worst locked room puzzle in an RPG ever.)

#5140205 Editing a Python Script during Runtime?

Posted by SiCrane on 18 March 2014 - 08:45 PM

How did you load it in the first place? If you imported it as a module then you can reload it with PyImport_ReloadModule().

#5139483 Is Python any good for...?

Posted by SiCrane on 16 March 2014 - 11:23 AM

Note that Python doesn't have to be as painful to embed as Vortez's code indicates. There are wrapper libraries for C++ like boost::python that make things significantly easier to work with.


One problem with Python as an embedded scripting language is that the CPython interpreter makes it very difficult to run Python scripts in a restricted execution environment (sandboxing).This isn't a big deal for some applications, but it can be a problem for games.

#5139265 Need help: a vector of different extended classes

Posted by SiCrane on 15 March 2014 - 11:28 AM

// removing entities
delete *it; // make sure to delete the entity being removed from the list

You're trying to delete an element you've just erased. You may want to reconsider your order of operations here.

#5135897 Memory overwrite after allocating 4k ints

Posted by SiCrane on 02 March 2014 - 01:50 PM

Im basically forcing the class to work inside vectors. (that Im assuming to require a copy ctor)

In C++ parlance, std::vector requires that the object it stores are copyable. std::vector expects to be able to copy objects as it reallocates or if existing objects are added to it.

This changes with C++11, which allows non-copyable objects if they are moveable. Of course you would need to properly implement your move constructor and move assignment operators so the amount of work is about the same.

#5133597 Smart Pointers Confusion

Posted by SiCrane on 22 February 2014 - 10:46 AM

Calling a member function on a deleted object is undefined behavior, which often means a crash, but can really do anything at all including succeeding. In this case I'm guessing that your member function doesn't actually use any member variables so doesn't actually access any deleted memory.