-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
184 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <stdlib.h> | ||
|
||
int main(void) | ||
{ | ||
int i; | ||
char *addr; | ||
|
||
i = 0; | ||
while (i < 1024) | ||
{ | ||
i++; | ||
} | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
void print(char *s) | ||
{ | ||
write(1, s, strlen(s)); | ||
} | ||
|
||
int main(void) | ||
{ | ||
int i; | ||
char *addr; | ||
|
||
i = 0; | ||
while (i < 1024) | ||
{ | ||
addr = (char*)malloc(1024); | ||
if (addr == NULL) | ||
{ | ||
print("Failed to allocate memory\n"); | ||
return (1); | ||
} | ||
addr[0] = 42; | ||
i++; | ||
} | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
void print(char *s) { write(1, s, strlen(s)); } | ||
|
||
void test(void *p); | ||
int main(void) { | ||
int i; | ||
char *addr; | ||
|
||
i = 0; | ||
while (i < 1024) { | ||
addr = (char *)malloc(1024); | ||
if (addr == NULL) { | ||
print("Failed to allocate memory\n"); | ||
return (1); | ||
} | ||
addr[0] = 42; | ||
free(addr); | ||
i++; | ||
} | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
#define M (1024 * 1024) | ||
|
||
void print(char *s) | ||
{ | ||
write(1, s, strlen(s)); | ||
} | ||
|
||
int main() | ||
{ | ||
char *addr1; | ||
char *addr2; | ||
char *addr3; | ||
|
||
addr1 = (char*)malloc(16*M); | ||
if (addr1 == NULL) | ||
{ | ||
print("Failed to allocate memory\n"); | ||
exit(1); | ||
} | ||
strcpy(addr1, "Hello world!\n"); | ||
print(addr1); | ||
addr2 = (char*)malloc(16*M); | ||
if (addr2 == NULL) | ||
{ | ||
print("Failed to allocate memory\n"); | ||
exit(1); | ||
} | ||
addr3 = (char*)realloc(addr1, 128*M); | ||
if (addr3 == NULL) | ||
{ | ||
print("Failed to reallocate memory\n"); | ||
exit(1); | ||
} | ||
addr3[127*M] = 42; | ||
print(addr3); | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <stdlib.h> | ||
|
||
#define M (1024 * 1024) | ||
|
||
int main() | ||
{ | ||
malloc(1); | ||
malloc(2); | ||
malloc(4); | ||
malloc(8); | ||
malloc(16); | ||
malloc(32); | ||
malloc(64); | ||
malloc(128); | ||
malloc(256); | ||
malloc(512); | ||
malloc(1024); | ||
malloc(1024 * 2); | ||
malloc(1024 * 4); | ||
malloc(1024 * 32); | ||
malloc(M); | ||
malloc(16*M); | ||
malloc(128*M); | ||
show_alloc_mem(); | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
void print(char *s) | ||
{ | ||
write(1, s, strlen(s)); | ||
} | ||
|
||
int main() | ||
{ | ||
int i; | ||
int alignment; | ||
char *addr; | ||
|
||
i = 1; | ||
alignment = 2 * sizeof(size_t); | ||
while (i <= 100) | ||
{ | ||
addr = (char*)malloc(i); | ||
if (addr == NULL) | ||
{ | ||
print("Failed to allocate memory\n"); | ||
exit(1); | ||
} | ||
if ((((unsigned long) (addr)) % alignment) != 0) | ||
{ | ||
print("malloc returned a non aligned boundary\n"); | ||
exit(1); | ||
} | ||
i++; | ||
free(addr); | ||
} | ||
} |