Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Dynamic Allocation

Name: Anonymous 2013-05-15 0:56



Ok, if I have a parent class defined. Note: don't worry about the name, it's just a class

Parent *p = new Parent();

That is saying, create a pointer p, and at location p, place a parent object, correct?

Just wondering if I understand.

Name: Anonymous 2013-05-15 1:32

The following happens:

1. A free block of size at least sizeof(Parent) on the heap is located.
2. If the free block is not found, a bad_alloc exception is thrown.
3. Otherwise, the found free block is marked as reserved in the heap data structure.
4. The constructor of Parent is applied to the free block.
5. The address of the free block is returned from the expression, (new Parent());
6. The address of the free block is assigned to the pointer, p.

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-05-15 7:05

>>2
You forgot about per-class allocators.

Best way to figure it out is look at the Asm output. Then write C code that creates almost the same output.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List