A simple, heavily annotated example that shows how all of the library's API methods (i.e., functions) and types can be used.
#define MY_MESSAGE "hello"
#define MY_MESSAGE_SUFFIX " world"
int main(void)
{
fprintf(
"Current lib<fancy_memory> library version: %d.%d.%d\n",
major,
minor,
revision);
char *my_string =
fancy_memory_malloc(memory_tracker,
sizeof(
char) * (strlen(MY_MESSAGE) + 1));
strcpy(my_string, MY_MESSAGE);
fprintf(
stdout,
"my_string = %s\n", my_string);
memory_tracker, my_string,
sizeof(char) * (strlen(MY_MESSAGE) + strlen(MY_MESSAGE_SUFFIX) + 1));
memcpy((my_string + strlen(MY_MESSAGE)), MY_MESSAGE_SUFFIX, strlen(MY_MESSAGE_SUFFIX));
my_string[strlen(MY_MESSAGE) + strlen(MY_MESSAGE_SUFFIX) + 1] = '\0';
fprintf(
stdout,
"my_string = %s\n", my_string);
exit(EXIT_SUCCESS);
}
fancy_memory_t * fancy_memory_create(void)
The factory method that needs to be used in order to instantiate a fancy_memory_t object.
void fancy_memory_free(fancy_memory_t *self, void *pointer)
The method that must be used to free (and stop tracking) memory previously allocated using the same f...
void fancy_memory_debug(fancy_memory_t const *self, FILE *stream)
A method that can be used to print (i.e., write) a summary of the tracked memory for self .
void * fancy_memory_malloc(fancy_memory_t *self, size_t size)
The method that must be used to allocate and track new memory.
struct fancy_memory_s fancy_memory_t
An opaque data type that is used as a container for storing "memory tracking" related data,...
Definition: fancy_memory.h:48
void fancy_memory_get_library_version(uint16_t *major, uint16_t *minor, uint16_t *revision)
A method that can be used to retrieve the library's current version. It works by populating the argum...
void * fancy_memory_realloc(fancy_memory_t *self, void *pointer, size_t size)
The method that must be used to reallocate (and update the tracking information of) memory that was i...
void fancy_memory_destroy(fancy_memory_t *self)
The method that should be used to destroy a fancy_memory_t object once that object is no longer neede...
size_t fancy_memory_get_total(fancy_memory_t const *self)
The method that must be used to retrieve the total amount of memory (in bytes) currently being tracke...