Memory Allocation

Memory Allocation - p should never be dereferenced after...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
8: Memory Deallocation Memory should be deallocated once the task it was allocated for has been completed. int *p; if ((p = malloc(1*sizeof(int))) == NULL) exit(EXIT_FAILURE);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Memory Deallocation Always follow the call to free(p) with
Background image of page 2
Memory Avoid mixing statically and dynamically allocated memory int i; int *p; &i = malloc(sizeof(int)); Memory deallocation using free() should
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Memory The value of a pointer
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: p should never be dereferenced after the call to free(p) . Do not create garbage objects, such as p = malloc(1*sizeof(int)); p = malloc(1*sizeof(int)); Memory Given two pointers p and q , the assignment p = q does not copy the block of memory pointed to by q into a block of memory pointed to by p Remember that after p = q ; p and q share the value;...
View Full Document

Page1 / 5

Memory Allocation - p should never be dereferenced after...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online