[OT] C++ question re. dyn. mem.
Will the free store be properly maintained when the following is executed?
// a simple object is defined
typedef struct
{
uint32_t a;
uint64_t b;
uint8_t c;
} t_my_type;
// allocate some memory for an instance of this object
t_my_type * p_a = (t_my_type) new t_my_type;
// change the way it is accessed to prove a point
int * p_b = (int *) p_a;
// p_a and p_b point to the same block of dyn. allocated memory;
// return the memory to free storage using the second pointer
delete p_b;
I think the free store will be maintained properly because there is a control
block attached to the allocated block of storage that defines the length of
the allocated memory.
TIA,
--
Mike Mueller
Reply to: