block allocation of classes

  • Thread starter Thread starter not_a_commie
  • Start date Start date
N

not_a_commie

I've got a search algorithm where I would like to allocate my nodes in
blocks. In other words, I would like to reserve enough memory for 200k
nodes and then just keep my own pointer into that block. I don't want
to do 200k small memory allocation calls. It seemed that this made
more sense when I was using structs. I could allocate a struct node[]
and then just work through that as I needed more nodes. Can I do the
same thing with classes?
 
Technically, you can't, not in the way you would an array of structures,
because each instance of the class has to be placed on the heap and you will
have to call the constructor individually to populate that array.

You would just be moving the time to allocate all those instances from
other areas of your program to the beginning, and I am guessing that it's
not going to make much of a difference.

Have you determined that memory allocation is a bottleneck for your
program? If not, then why change it?
 
Back
Top