![]() |
|
#1
|
|||
|
|||
Dynamic allocation and container objectsa class (class 1) uses a dynamically allocated array. the default constructor for class 1 simply assigns a NULL value to the pointer that would be used to access the dynamically allocated array and allocates no memory for that array. if an array of objects of class 1 were allocated, and memory was, later, allocated for (at least some of) the arrays within those objects, would that cause a segmentation fault/ruin data in the array?
|
|
#2
|
|||
|
|||
Re: dynamic allocation and container objectsQuote:
1. Make an example that does this. That is: allocates memory and then puts something in it and then passes the address to some other part of the program (causes the pointer in the object to reference that block). 2. Look at the code. 3. Realize that that once a program has obtained the address of a block of memory by using the new operator (or one of the malloc family of allocation functions), that block of memory belongs to that program until either the program terminates or the block is returned to the operating system by use of the delete operator (or the free() function). Whatever you put into that block stays there until that program de-allocates it or overwrites it with something else. 4. Look at your code and see where it uses one of the allocation functions and passes the address along to other parts of the program. 5. Look at your code and see where the memory was deallocated. 6. Draw your conclusion. If you still have questions, then post the code that you are considering and tell us what you don't understand. Regards, Dave |
Recent GIDBlog
Halfway done! by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Do I need RTTI? | edt | C++ Forum | 7 | 25-Aug-2006 13:26 |
| Dynamic vs Static Arrays | WaltP | Miscellaneous Programming Forum | 5 | 16-Feb-2006 15:54 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The