mmap anonymous

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-08-11 00:00:02 +00:00
parent c03d5d18ea
commit b1767533af
8 changed files with 92 additions and 23 deletions

View File

@@ -5,18 +5,27 @@
#include <stdlib.h>
int main(void) {
size_t bytes = sizeof(int) * 2;
/* Allocate 2 ints. */
int *is = malloc(bytes);
int *is;
size_t nbytes = 2 * sizeof(*is);
/* Allocate 2 ints. Note that unlike traditional stack arrays (non-VLA)
* this value does not have to be determined at compile time! */
is = malloc(nbytes);
/* This can happen for example if we ask for too much memory. */
if (is == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
/* Write to and read from the allocated memory. */
is[0] = 1;
is[1] = 2;
assert(is[0] == 1);
assert(is[1] == 2);
/* Free the allocated memory. */
free(is);
return EXIT_SUCCESS;
}