Mercurial > sos > sos
view src/dynamic.c @ 26:c1ad124f2aaf
Re-did errors for pop, added some nice testing for dynamic memory
I now have a decent test program for dynamic memory implemented as a separate
program (dynamic.c)
The stack now stores its current size, this is used in operations.c to check
the size
Pop should now also be called with a pointer to an eltType. Description of
behavior is in stack.h
author | Jonathan Pevarnek <pevarnj@gmail.com> |
---|---|
date | Sun, 20 Mar 2011 14:17:24 -0400 |
parents | 2b19746a4e97 |
children | 1a070e843bf6 |
line wrap: on
line source
/* * This is where everything starts */ #include <std.h> #include <operations.h> #include <stack.h> void dumpBuffer(char *a, int b) { int i; for(i = 0; i < b; i++) { int foo = (int) a[i]; char c[10]; itoa(foo, c, 16); sPrint(c); sPrint(" "); if(!((i + 1)%20)) sPrint("\n"); } } void start(u64 __memsize) { malloc_init(__memsize - HEAP_START); size_t n; char *buffer; char input[30]; while(0) { sPrint("How long do you want the string? "); n = atoi(sGet(input, 30)); buffer = (char*) malloc(n); if (!buffer) { //allocation failed, too large sPrint("ERROR\n"); break; } // size_t i; // for (i = 0; i < n - 1; i++) // buffer[i]='a'; //I need to make rand... // buffer[n - 1]='\0'; // sPrint(buffer), sPrint("\n"); // dumpBuffer(buffer, n); sPrint(append(itoa((unsigned long)buffer, input, 16), "\n")); free(buffer); } printMem(); Stack *stack = stack_init(); for(n = 0; n < 1000; n++) { push(stack, n); } stack_destroy(stack); printMem(); void *a = malloc(1223); void *b = malloc(352); void *c = malloc(3539); void *d = malloc(325); printMem(); free(b); printMem(); b = malloc(400); printMem(); sPrint("DONE\n"); for(;;) sGet(input, 0); }