Linux Kernel, System
[Linux/System] Allocate Space in the Stack
RevDev
2016. 4. 25. 21:45
[Malloc]
-Allocate Space in the Heap.
Reference:
void* malloc (size_t size);
1 2 3 4 5 6 7 8 9 10 11 12 | #include <stdio.h> int main() { const char *strHello = "Hello Heap Allocate!"; char *ptrHello; ptrHello=(char *)malloc(strlen(strHello)+1); strcpy(ptrHello,strHello); printf("%s",ptrHello); free(ptrHello); return 0; } | cs |
[Alloca]
-Allocate Space in the Stack.
Reference:
void* alloca (size_t size);
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <stdio.h> #include <alloca.h> int main() { const char *strHello = "Hello Stack Allocate!"; char *ptrHello; ptrHello=alloca(strlen(strHello)+1); strcpy(ptrHello,strHello); printf("%s",ptrHello); return 0; } | cs |