So in my program I have a contiguous array of objects. I am doing this because I want spatial locality between each of these objects. They are really small and in a very large array and are iterated over in order.
As such I initialize them like this
memoryPool = new Object[MAX_OBJECTS];
This of course calls the default initializer on every single one of the objects. I wrote no default initializer And that is completely fine as they will be over written. They cant be initialized to a valid state at the beginning because they need to be initialized with data generated later down the road at various times.
There is therefore a variable objectCount
the objectCount
has been initialized with the valid initializer. When it is time to increase the objectCount variable
assert(newObjectCount >= objectCount);
for (int i = objectCount; i < newObjectCount; i++) {
new(&(memoryPool[i])) Object(/*Calls the valid initializer of the class*/);
}
objectCount = newObjectCount;
This technique which uses the placement new I found here.
So you can see that I maintain spatial locality between these classes like so.
There may be a better way to do this but I dont know of one and I am all ears.
Now on to the actual question. This code when ran through valgrind with leak-check=full generates a LOT of output about Conditional jump or move depends on uninitialized value(s)
and it is always on one of the Object
objects. Will this sort of allocation be on of the "funny things with pointers" that could throw off Memcheck?