Jump to content

  • Log In with Google      Sign In   
  • Create Account


zacaj

Member Since 18 Sep 2008
Offline Last Active Sep 28 2013 03:05 PM

Posts I've Made

In Topic: potatoeses or potatoeseses

27 September 2013 - 07:23 PM

If you insist on doing it that way, then malloc is indeed what you want to use if you want to allocate the memory for them without calling the constructors.  You just have to be careful that the first bit of memory in each object doesn't ever end up being zero, otherwise your check wouldn't work.  

 

Alternately, just have an empty constructor.  


In Topic: Using STL Maps

27 September 2013 - 06:03 PM

Since you didn't allocate them using new there won't be a memory leak


In Topic: potatoeses or potatoeseses

27 September 2013 - 04:36 PM

If you want to use any inheritance then you need to story individual pointers to objects, so the 4 bytes are required anyway (and it's not like 4 bytes per object will actually make an impact).  If you only have one object then I'd suggest just giving them a bool active variable and then just setting it to zero to show that they're 'dead' or whatever.  As to the unbearableness, it only affects maybe three lines of your code, and besides, you *are* using C++.  What did you expect?  

 

really though, unless there's some big reason why you're using an array like this, I'd recommend you switch to using a std::vector<SomeObject*>


In Topic: potatoeses or potatoeseses

27 September 2013 - 04:14 PM

Off the top of my head, try

SomeObject **so;

so = new SomeObject*[max_objects];

An array is a pointer to a block of memory, so in your case you want a pointer to a block of pointers that you can then individually allocate


In Topic: Why do I get ridiculous floating point values when I read a binary file?

31 July 2013 - 12:55 PM

Try using a union

union FloatInt
{
    int i;
    float f;
}

FloatInt fi;
fread(&fi.i,sizeof(FloatInt),1,fp);

Are you sure blender wrote a float and not a double?


PARTNERS