The mm malloc and mm free functions have the same

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: time, after the value of Ò becomes known. With this approach, the maximum size of the array is limited only by the amount of available virtual memory. 1 2 3 4 5 6 7 8 9 10 11 12 #include "csapp.h" int main() { int *array, i, n; scanf("%d", &n); array = (int *)Malloc(n * sizeof(int)); for (i = 0; i < n; i++) scanf("%d", &array[i]); exit(0); } Dynamic memory allocation is a useful and important programming technique. However, in order to use allocators correctly and efficiently, programmers need to have an understanding of how they work. We will discuss some of the gruesome errors that can result from the improper use of allocators in Section 10.11. 10.9.3 Allocator Requirements and Goals Explicit allocators must operate within some rather stringent constraints. 10.9. DYNAMIC MEMORY ALLOCATION 527 ¯ Handling arbitrary request sequences. An application can make an arbitrary sequence of allocate and free requests, subject to the constraint that each free request must correspond to a currently alloc...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online