function has a frame where its local variables are stored. This memory is automatically allocated when a function starts and automatically deallocated when the function ends. In fact, local variables are sometimes called automatic variables because of this convenient behavior.
Sometimes, however, you need to claim a contiguous chunk of memory yourself – a buffer. Programmers often use the word buffer to mean a long line of bytes of memory. The buffer comes from a region of memory known as the heap, which is separate from the stack
// Declare a pointer float *startOfBuffer; // Ask to use some bytes from the heap startOfBuffer = malloc(1000 * sizeof(float)); // ...use the buffer here... // Relinquish your claim on the memory so it can be reused free(startOfBuffer);
No comments:
Post a Comment