Memory Explorer is a C program that implements and benchmarks three data structures for storing user scores:
- Dynamic Array
- Linked List
- Hash Table
Used ChatGPT to review my code to make sure there’s no memory leaks
Memory Explorer is a C program that implements and benchmarks three data structures for storing user scores:
Used ChatGPT to review my code to make sure there’s no memory leaks
This is my first project in C, and I’m really proud of it, because now it can do exactly what I wanted to learn C for: memory management to create special data structures that I can manipulate myself.
The benchmark stats look great, and it’s nice to know hash tables are actually simple to implement, but also reduce operation time a lot.
I implemented hash table from start to finish, it was very simple as it was just an array of linked lists.
load function to load the data from the text fileunload function to free all the memory so there are no memory leaksadd_data function to add a data entry to the hash tabledisplay function to display all the data entries in the hash tablesearch_data function to find a specific data entry in the hash tableamend_data function to amend the score of a specific data entry in the hash tableremove_data function to remove a specific data entry in the tableThe output below is the same as in linked lists, hopefully hash table is actually faster.
Next entry will be about comparing hash tables, linked list, and dynamic array.
Log in to leave a comment
I’ve decided to not include sorting in this project.
load function in linked lists, which initialises a linked list with the data in the text file providedunload function, which frees all the memory in the linked listdisplay function, which displays all the data in the linked listLog in to leave a comment
Hopefully this is the penultimate devlog for the dynamic array data structure.
This morning I:
amend_data function, which amends the score of a user in the dynamic arraymain function so it’s readableremove_data function, which deletes the data entry of the user with the username given as a parameter, and returns the pointer to the new memorychar username[50] to const char *username in most places, since I don’t want it to changesscanf
remove_data, since it’s not neededNow all that’s left to do is create the sort_data function, in which I’m planning on using merge sort.
Log in to leave a comment
add_data function which adds a data entry to the dynamic entry, and returns the new pointersearch_data function which searches for the score of the user with the username given in the parameterLog in to leave a comment
load function more robust so it increments size more logically, and it closes files if a pointer fails to be createdunload function, which simply contains one line to free the pointer (dynamic arrays are easy to free)display function which goes through all the entries in the dynamic array and displays each oneLog in to leave a comment
split function, but I can parse the data from the text file nowunload function, which I’m going to code nextLog in to leave a comment
I’ve changed the idea of this project a little, although it’ll still be exploring memory in C
The project will contain a data type of a leaderboard entry, and I’ll include different ways of storing multiple leaderboard entries as different data structures.
I’ll definitely be doing:
And I’m also planning on researching and implementing 2 others.
I’ve started working on the dynamic array, and have structured out the different functions that I’ll need to implement
Log in to leave a comment
Log in to leave a comment