Originally Posted by
Araanor
No, I don't want char. I don't even want an array of my_object. I want a region of memory where I can put my objects. CornedBee made a good post on how this is possible. I'd only be casting from void*, and only when new memory is allocated.
The point was, if you want char (which you don't), then you allocate
Code:
char* p = new char[num];
delete p;
If you want my_obj (which you don't), then you do:
Code:
my_obj* p = new my_obj[num];
delete p;
And if you simply want void* (which basically char* is the same as), you do:
Code:
void* p = ::operator new(size);
::operator delete(p);
The point is, you allocate and delete the memory with the same. You delete the same type. Don't allocate char and delete as void, or allocate my_obj and delete as char, or whatever. As long as you delete the original pointer (or another pointer, in either case, w/o changing the type), it works as intended.
But it's also silly to allocate memory of a different type than you want. You don't want to allocate char when you want my_obj, or vice versa. Char works fine as a contigous memory block (because it's 1 byte), but you can use the raw operator new for that, I guess.
Just so we're clear, yes?