Skip to content

A library that I wrote to simplify memory management across a number of my C programming assignments.

Notifications You must be signed in to change notification settings

benwainwright/autoFree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Autofree

This library was written by me as part of the C Programming unit at Bristol University. It is designed to simplify the process of managing memory in C.

Calls to malloc() are replaced via the C Preprocessor by a function that calls malloc(), then adds the memory address to an internal data structure.

This data structure is initialised with a call to newHeapList() and is series of linked lists which are each chained together by their initial node. This way, every call to malloc() adds a pointer to the most recent chain, which can then be iterated and deallocated using freeHeapList(). In order to simplify this process further, newHeapList() and freeHeapList() can be implicitly called using an AUTOFREE block as shown below:

int main()
{
   AUTOFREE {
      char* foo = malloc(20);
      char* bar = malloc(25);
   }
}

In the above example, foo and bar will be automatically deallocated when the containing AUTOFREE block exits. It should be noted that this library does NOT at this stage handle calls to reallocate()

About

A library that I wrote to simplify memory management across a number of my C programming assignments.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages