J
Joe The Smoe
Hi,
to manage memory allocation for a multi-threaded application and reduce
the use of mutex, each thread is given an object of a class named "pool"
which allocates, recycles and eventually releases a set of memory
blocks (the classical memory pool).
The different objects allocated by each thread can now be allocated
using the given pool object thanks to a placement new and new[]
operators given to each concerned class.
The problem I meet is that I have something working pretty well except
for the placement new[] which places the first element of the array 4
bytes after the address returned by the new[] operator. This causes me
some problem at the time the array has to be released because the memory
address of the array (the address of the first element) does not match
the address given by the pool to the placement new[] operator (for the
pool this is not a memory block that it has allocated).
OK, I could shift the array address by four bytes and it would work but,
I'd rather like to understand.
Thanks for any enlightenment!
Cheers,
Joe.
P.S: the placement new, new[], delete, and delete[] operators are
textually identical for each class, I can use a #define macro to add
them to each class. But, is there a better C++ way of doing that?
to manage memory allocation for a multi-threaded application and reduce
the use of mutex, each thread is given an object of a class named "pool"
which allocates, recycles and eventually releases a set of memory
blocks (the classical memory pool).
The different objects allocated by each thread can now be allocated
using the given pool object thanks to a placement new and new[]
operators given to each concerned class.
The problem I meet is that I have something working pretty well except
for the placement new[] which places the first element of the array 4
bytes after the address returned by the new[] operator. This causes me
some problem at the time the array has to be released because the memory
address of the array (the address of the first element) does not match
the address given by the pool to the placement new[] operator (for the
pool this is not a memory block that it has allocated).
OK, I could shift the array address by four bytes and it would work but,
I'd rather like to understand.
Thanks for any enlightenment!
Cheers,
Joe.
P.S: the placement new, new[], delete, and delete[] operators are
textually identical for each class, I can use a #define macro to add
them to each class. But, is there a better C++ way of doing that?