What am I missing?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
roninmagus
Posts: 91
Joined: Fri Oct 31, 2003 5:03 am

What am I missing?

Post by roninmagus »

I'm trying to replace STL stuff in my project, so I'm using irr::core::array instead of stl's vector. I am getting errors because I use the modulus operator on a value returned from array::size(), because it returns 0 when I don't think it should.

Why is array::size not returning the correct value? Am I initializing it incorrectly?

Code: Select all

			std::cout << "Creating 1000 unit hash map" << std::endl;
			hashVector.reallocate(1000);
			std::cout << "Size of hashvector: " << hashVector.size() << std::endl;
This code doesn't use the modulus operator, but it is executed before using it so it should work correctly. Unfortunately, I get this output:
Creating 1000 unit hash map
Size of hashvector: 0
?!?? Any idea why this is not working as it should? Isn't reallocate the correct function to use?
daveandrews.org - A Christian Programmer's Weblog | Dusty Engine - A Task Engine for Irrlicht
Gorgon Zola
Posts: 118
Joined: Thu Sep 18, 2003 10:05 pm
Location: switzerland

Post by Gorgon Zola »

hi roninmagus

reallocate just allocates the memory for the given amount of units.
size returns the actually used places in the array.

please take a look at the source for further information.

regards
tom
roninmagus
Posts: 91
Joined: Fri Oct 31, 2003 5:03 am

Post by roninmagus »

Ahhh.. I see my problem, I'll get it working when I get home. I learn a little more about Irrlicht each day :)

Thank you much!
daveandrews.org - A Christian Programmer's Weblog | Dusty Engine - A Task Engine for Irrlicht
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

You might try set_used() to set the size. It does a reallocate (only if necessary) and sets the the internal count of used units to the given number.

Code: Select all

hashVector.set_used(1000);
But still have a look at the source or API doc.
Post Reply