Compare commits
5 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ae1af7a053 | ||
![]() |
b3fa94b0e0 | ||
![]() |
e766295d68 | ||
![]() |
264146a7e1 | ||
![]() |
030ba0d75f |
1 changed files with 50 additions and 27 deletions
|
@ -20,41 +20,64 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
|
||||
int print_usage() {
|
||||
printf("usage: [size mb/kb/b]");
|
||||
printf("usage: size mb/kb/b [chunks]\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int m = 0;
|
||||
uint32_t size = 0;
|
||||
if(argc <= 2)
|
||||
print_usage();
|
||||
if(argc == 3) {
|
||||
if(!strcmp(argv[2], "mb"))
|
||||
m = 1024*1024;
|
||||
else if(!strcmp(argv[2], "kb"))
|
||||
m = 1024;
|
||||
else if(!strcmp(argv[2], "b"))
|
||||
m = 0;
|
||||
else
|
||||
print_usage();
|
||||
}
|
||||
if(argc > 3)
|
||||
print_usage();
|
||||
|
||||
size = atoi(argv[1]);
|
||||
if(size <= 0)
|
||||
int multp = 0;
|
||||
int size = 0;
|
||||
int chunks = 1;
|
||||
|
||||
void **test;
|
||||
|
||||
if (argc <= 2 || argc > 4)
|
||||
print_usage();
|
||||
|
||||
size *= m;
|
||||
uint8_t* test = malloc(size);
|
||||
printf("malloc(%d) - START: %p END: %p \n", size, test, test + size);
|
||||
size = atoi(argv[1]);
|
||||
if (size <= 0)
|
||||
print_usage();
|
||||
|
||||
if (!strcasecmp(argv[2], "mb"))
|
||||
multp = 1024*1024;
|
||||
else if (!strcasecmp(argv[2], "kb"))
|
||||
multp = 1024;
|
||||
else if (!strcasecmp(argv[2], "b"))
|
||||
multp = 1;
|
||||
else
|
||||
print_usage();
|
||||
size *= multp;
|
||||
|
||||
if (argc == 4)
|
||||
chunks = atoi(argv[3]);
|
||||
|
||||
test = malloc(chunks * sizeof(void *));
|
||||
if (!test)
|
||||
printf("malloc(%d) - FAILED!\n", chunks * sizeof(void *));
|
||||
|
||||
// allocate...
|
||||
int i;
|
||||
for (i = 0; i < chunks; i++) {
|
||||
test[i] = malloc(size);
|
||||
if (test[i])
|
||||
printf("malloc(%d)\tCHUNK: %d START: %p END: %p\n", size, i, test[i], test[i] + size);
|
||||
else {
|
||||
printf("malloc(%d)\tFAILED! Abort allocation, start with freeing memory\n", size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// and release again
|
||||
for (i = 0; i < chunks; i++) {
|
||||
if (test[i]) {
|
||||
free(test[i]);
|
||||
printf("free(%p)\tCHUNK: %d\n", test[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
free(test);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue