This commit is contained in:
p-w-rs
2022-09-07 11:18:56 -05:00
commit 7bb91e666d
121 changed files with 5306 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
#include <stdio.h>
#include <stdlib.h>
#include "memory_manager.h"
/*
* Using static causes the compiler to
* limit visibility of the variables to this file only
* This can be used to simulate 'private' variables in c
*/
static int allocation_count = 0;
/* TODO Define additional structure definitions here */
/* mmInit()
* Initialize the memory manager to "manage" the given location
* in memory with the specified size.
* Parameters: start - the start of the memory to manage
* size - the size of the memory to manage
* Returns: void
*/
void mmInit(void* start, int size)
{
allocation_count = 0;
// TODO more initialization needed
}
/* mmDestroy()
* Cleans up any storage used by the memory manager
* After a call to mmDestroy:
* all allocated spaces become invalid
* future allocation attempts fail
* future frees result in segmentation faults
* NOTE: after a call to mmDestroy a call to mmInit
* reinitializes the memory manager to allow allocations
* and frees
* Parameters: None
* Returns: void
*/
void mmDestroy()
{
}
/* mymalloc_ff()
* Requests a block of memory be allocated using
* first fit placement algorithm
* The memory manager must be initialized (mmInit)
* for this call to succeed
* Parameters: nbytes - the number of bytes in the requested memory
* Returns: void* - a pointer to the start of the allocated space
*/
void* mymalloc_ff(int nbytes)
{
return NULL;
}
/* mymalloc_wf()
* Requests a block of memory be allocated using
* worst fit placement algorithm
* The memory manager must be initialized (mmInit)
* for this call to succeed
* Parameters: nbytes - the number of bytes in the requested memory
* Returns: void* - a pointer to the start of the allocated space
*/
void* mymalloc_wf(int nbytes)
{
return NULL;
}
/* mymalloc_bf()
* Requests a block of memory be allocated using
* best fit placement algorithm
* The memory manager must be initialized (mmInit)
* for this call to succeed
* Parameters: nbytes - the number of bytes in the requested memory
* Returns: void* - a pointer to the start of the allocated space
*/
void* mymalloc_bf(int nbytes)
{
return NULL;
}
/* myfree()
* Requests a block of memory be freed and the storage made
* available for future allocations
* The memory manager must be initialized (mmInit)
* for this call to succeed
* Parameters: ptr - a pointer to the start of the space to be freed
* Returns: void
* Signals a SIGSEGV if a free is not valid
* - memory manager is not initialized
* - memory manager has been destroyed
* - ptr is not allocated (e.g. double free)
*/
void myfree(void* ptr)
{
}
/* get_allocated_space()
* Retrieve the current amount of space allocated by the memory manager (in bytes)
* Parameters: None
* Returns: int - the current number of allocated bytes
*/
int get_allocated_space()
{
return 0;
}
/* get_remaining_space()
* Retrieve the current amount of available space in the memory manager (in bytes)
* (e.g. sum of all free blocks)
* Parameters: None
* Returns: int - the current number of free bytes
*/
int get_remaining_space()
{
return 0;
}
/* get_fragment_count()
* Retrieve the current amount of free blocks (i.e. the count of all the block, not the size)
* Parameters: None
* Returns: int - the current number of free blocks
*/
int get_fragment_count()
{
return 0;
}
/* get_mymalloc_count()
* Retrieve the number of successful malloc calls (for all placement types)
* Parameters: None
* Returns: int - the total number of successful mallocs
*/
int get_mymalloc_count()
{
return allocation_count;
}