Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- #include <malloc.h>
- #include <assert.h>
- const size_t mem_size = 16L * 1024*1024*1024;
- const size_t block_size = 20 * 1024 * 1024;
- const size_t blocks_count = (mem_size / block_size) / 2;
- int main() {
- void* p;
- /*{
- p = malloc(block_size);
- free(p);
- }*/
- printf("Allocate 1/2 of the main memory\n");
- void** blocks = new void*[blocks_count];
- for (size_t i = 0; i < blocks_count; ++i) {
- blocks[i] = malloc(block_size);
- memset(blocks[i], 0, block_size);
- }
- printf("Free 1/4 of the main memory\n");
- for (size_t i = 0; i < blocks_count; i+=2)
- free(blocks[i]);
- printf("Allocate big array (1/2 of the main memory)\n");
- p = malloc(mem_size / 2);
- printf("Initialize big array\n");
- memset(p, 0, mem_size / 2);
- printf("OK\n");
- free(p);
- delete [] blocks;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement