Re: My solution to allocating memory
- From: vippstar@xxxxxxxxx
- Date: Thu, 31 Jan 2008 02:21:17 -0800 (PST)
Here is an example snippet with this code.
-- snip.c --
#include "xmalloc.c"
void oh_no(void) { fprintf(stderr, "Something went wrong.\n"); }
int main(void) {
size_t n;
void *p;
xmalloc_init();
atexit(oh_no); /* its just an example so i dont check return value
*/
for(n = 0; n < 1024; n++)
(void)xmalloc(1, 0); /* no memory leak, the pointer is held
somewhere */
printf("allocated 1024 xmalloc(1, 0)!\n");
xmalloc_end(); /* free our resources */
xmalloc_init();
p = xmalloc(sizeof "hello world\n", 0);
strcpy(p, "hello world\n");
printf("%s", p);
xfree(p);
return 0;
}
-- snip.c --
.
- References:
- My solution to allocating memory
- From: vippstar
- My solution to allocating memory
- Prev by Date: My solution to allocating memory
- Next by Date: Re: Function with unspecified number of arguments
- Previous by thread: My solution to allocating memory
- Next by thread: Quick check on signed promotion of bytes
- Index(es):
Relevant Pages
|