0% found this document useful (0 votes)
131 views

Memmanagerdocumentation

The goal of the memory manager is to manage memory from an array. This program allocates memory into an array, frees memory in the array, reallocates data by trying to expand the current location and adds the new dataset to the end of the array list. Also, this program is able to defragment the memory array.

Uploaded by

api-285553674
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views

Memmanagerdocumentation

The goal of the memory manager is to manage memory from an array. This program allocates memory into an array, frees memory in the array, reallocates data by trying to expand the current location and adds the new dataset to the end of the array list. Also, this program is able to defragment the memory array.

Uploaded by

api-285553674
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

WindowsMemoryManagerAssignment

MatthewOwenJones
s2954932

Contents

1.

ProblemStatementp1

2.

UserRequirementsp2

3.

SoftwareRequirementsp2

4.

SoftwareDesignp3

5.

RequirementAcceptanceTestsp9

6.

DetailedSoftwareTestingp10

7.

UserInstructionsp11

1. ProblemStatement
Thegoalofthememorymanageristomanagememoryfromanarray.Thisprograms
constructorsetsthethesizeofmemorytobemanagedto0bytesiftheuserdoesnt
specifythesizeofbytestheywanttomanage.Furthermore,thisprogramallocates
memoryintoanarray,freesmemoryinthearray,reallocatesdatabytryingtoexpand
thecurrentlocationandifthereisntenoughroomtoexpanditfreesthatdatasetand
addsthenewdatasettotheendofthearraylist.Also,thememorymanagerreturns
thetotalamountoffreememory,thecontentsofmemoryconvertedtohexandthe
contentsofmemory.Also,thisprogramalsooverloadstheoutputstreamoperatorto
actlikethedumpfunctionthatwillbecoveredinthisreportandoverloadsthe
equalssignforadeepcopyofamemorymanagerisabletobeperformed.Finally,
thisprogramisabletodefragmentthememoryarray.

2. UserRequirements

Thefollowingoutlinestheuserrequirementsfortheprogram:

Theuserwillbeabletoinitialiseasmanymemorymanagersastheywant.
Eachonecanbeinitialisedtoasizeorwithoutasize,whichinitialisesitto0.
Onceinitialised,theusercan:
Allocatedatatothevirtualmemoryarray
Freedatafromthevirtualmemoryarray
Expandasegmentofmemoryorfreeitandaddtotheend
Defragmentthevirtualmemoryarray
Getthetotalamountoffreebytesofmemory
Dumpoutmemorycontentsashexandthedatainthevirtualmemory
Outputthecontentsashexandthedatafromthevirtualmemorybyimplicitly
callingcout<<nameofmemorymanager<<endl

3. SoftwareRequirements
1.
2.
3.
4.
5.
6.
7.
8.
9.

Createaninitialmemoryarray.
Freeallmemoryresources.
Allocatememoryinmemoryarrayandreturnapointertotheallocatedmemory.
Deallocatememory.
Expandallocatedmemorysize,ifthereisntenoughroomtoexpand,freeitand
allocatethenewdatatotheendofthememoryarray.
Defragmentmemoryarray.
Returnthetotalamountoffreememoryinmemoryarray.
Printoutrawmemorycontentsashexandreturnthememorycontents
Conductadeepcopy

4. SoftwareDesign

HighLevelDesignLogicalBlockDiagram

StructureChart
MemManager
virtualMemory
char*
clength
int
maxlength
int
freebits
int
________________________________________________________________
+MemManager(int)
~MemManager()
+void*Alloc(int)
+voidFree(void*)
+void*Realloc(void*,int)

+voidCompact()

+intAvail()

+voidDump()

+char*toString()

+friendostream&ostream&operator<<(ostream&,consMemManager&)
+MemManager&operator=(constMemManager&)

Listofallfunctionsinthesoftware.
MemManager(int max_size = 0)
This function initialises the memory manager. It initialises the clength to 0 (current
length), maxlen to max_size, freebits to max_size and virtualMemory to an array of
characters of max_size. If the user doesnt specify an integer in the parenthesis, this
function will initialise a memory manager of size 0, otherwise it will initialise it to the size
specified. This function doesnt return any value, it simply initialises the memory
manager.
~MemManager()
This function does not take any parameters and is called by default when the program is
exited. This function sets clength, maxlen and freebits to 0 and deletes the virtual
memory. This function is the destructor for the program.
Alloc(int)
This function allocates data in the virtual memory array and returns a pointer to the start
of the data that is being allocated. This function tries to allocated the size specified in line
(in the memory fragments) if there is enough room, if there isnt enough room to allocate
data in line, it allocates the data to the end of the virtual memory array. If there isnt
enough room to allocate that data, this function will return NULL. The parameter for
this function is an integer. This function returns a pointer to the first position of the data
that has been allocated.
Free(void*)
This function removes the data at the memory address specified in the parameters. This
function searches through the virtualMemory array and tries to find the pointer specified.
If the pointer is found in virtualMemory, this function will set all the data from that
4

location until after the null character to = (the not allocated key) so that data can be
reallocated using the Alloc() function. Free(void*) function does not return any value.
Realloc(void*, int)
This function tries to enlarge the size of the allocated at the location given by the pointer,
if its not possible to enlarge that allocated data, the data allocated at that pointer is
deleted and a new allocation is made of the size specified to the end of the
virtualMemory. A pointer to the beginning of the allocated data is returned or NULL if
the reallocation was not possible.
Compact()
This function removes all of the memory fragments in the virtualMemory array. This
function takes in no parameters, and removes all the free data between the beginning of
the virtualMemory array and the end of the allocated data in the virtualMemory array.
This function may loose references to pointers made from allocating data because the
array is deleted and recreated in the process of removing memory fragments from the
virtualMemory array.
Avail()
This function returns all of the free bytes of memory in the virtualMemory array. This
function does not take any parameters, and returns an integer of the amount of free bytes
of memory left in virtualMemory. This function will return the total amount of free bytes
of memory. This includes the free memory fragments.
Dump()
This function prints out the the raw memory contents of the virtualMemory array in
consecutive rows of 16 hexadecimal values with a single space between each one. Also,
this function prints out the contents of virtualMemory array in rows of 16 characters
separated by a single space. This function does not take any parameters and has no return
value.
toString()
This function returns a char pointer to the first element in the virtualMemory array. This
function takes no parameters.
ostream&ostream&operator<<(ostream&,consMemManager&)
Thisfunctionoverloadstheoutputstreamoperatortoprintoutthecontentofthe
memorymanagerinrowsof16hexadecimalvaluesandthenrowsof16charactersof
thememorymanagersvirtualMemoryarray.Thisfunctiontakesamemorymanager
asanargumentandiscalledwiththecout<<thenthenameofthememory
managertheuserwishestoprintout.Thisfunctionreturnstheoutputstream.

MemManager&operator=(constMemManager&)
Thisfunctionoverloadsthe=operatortomakeadeepcopyofamemorymanager.
Thisfunctionpopulatestheclength,maxlenandfreebitsofthememorymanagertobe
returnedandpopulatesthevirtualMemoryarrayofthememorymanagertobe
returnedtohavethesamedataasthememorymanagerspecified.Thedeepcopied
memorymanagerisreturned.
5


Listofalldatastructuresinthesoftware.(eglinkedlists,trees,arrays
etc)
char*virtualMemory
Thisdatastructureisanarrayofchars.Itisusedtomanageasetamountofdata.The
managementofthisdataisconductedthroughtheuseofthefollowingfunctions:
Alloc(),Realloc(),Free()andCompact().Thesefunctionsallocate,freeandeditdata
inthearray.Acounterisusedtokeeptrackofthecurrentwritingpositiontowrite
dataintothearraythroughthevariableclength.Thetotalamountoffreebytesof
memoryarestoredinavariablecalledfreebits.Allthefunctionsthataccess
virtualMemoryare:MemManager,~MemManager,Alloc,Free,Realloc,Avail,
Dump,CompactandtoString.
DetailedDesignPseudocodeforall
nonstandardandnontrivial
algorithmsthatoperateondatastructures

Allocatingdata:
if(enoughroomtoallocatememory)
{
if(virtualMemoryisempy)
{
allocatedataatthefrontofthearray
returnpointertofrontofarray
}else
{
checkifenoughroomexiststoallocatedatainmemoryfragments
if(enoughroomtoallocateinmemoryfragments)
{
allocatedatainfragments
returnpointertostartofdataallocated
}else
{
allocatedataattheend
returnpointertostartofdataallocated
}
}
}else
{
returnNULL
}

Free:
if(pointerexistsinvirtualMemory)
{
deleteallmemoryuntildata==NULL
deletetheNULLcharacter
6

Realloc:
if(pointerexistsinvirtualMemory)
{
if(enoughroomexiststoexpandthisallocateddatatothesizegiven)
{
expandallocateddata
returnpointertoallocateddata
}else
{
free(pointer)
allocatenewdatatotheendofvirtualMemory
returnpointertostartofdataallocated
}
}

Compact:
for(everyelementinvirtualMemory)
{
if(virtualMemory[element]===(freebit))continue
copydataatthislocationinvirtualMemoryintoanotherarray
keeptrackofhowmanysegmentsareaddedtonewarray
}
delete[]virtualMemory
virtualMemory=newchar[maxlen]
for(everysegment)
{
copyeachsegmentinnewarrayintovirtualMemory
deletenewarray
}

Avail:
returnfreebits

Dump,<<:
for(everyelementinvirtualMemory)
{
printouthexrepresentationofthevaluestoredatthatlocationandasinglespace
if(every16thelement)
{
printanewline
}
}
for(allelementsinvirtualMemory)
{
printoutcharatvirtualMemory[elements]
printaspace
7

if(every16thchar)
{
printanewline
}
}

toString:
returnspointertostartofvirtualMemory

=:
copyallvariablestonewmemorymanager.
for(allelementsinvirtualMemory)
{
copyvirtualMemory[element]intonewmemorymanager
returnapointertothenewmemorymanager
}

RequirementAcceptanceTests

Software
Requiremen
tNo

Test

Implemented TestResults
(Full/Partial/ (Pass/Fail)
None)

Theuserwillbeabletoinitialiseasmanymemory
managersastheywant
Eachonecanbeinitialisedtoasizeorwithoutasize,
whichinitialisesitto0
Allocatedatatothevirtualmemoryarray
Freedatafromthevirtualmemoryarray

FULL

PASS

FULL

PASS

FULL
FULL

PASS
PASS

Expandasegmentofmemoryorfreeitandaddtothe
end
Defragmentthevirtualmemoryarray

FULL

PASS

FULL

PASS

Getthetotalamountoffreebytesofmemory
Dumpoutmemorycontentsashexandthedatainthe
virtualmemory
Outputthecontentsashexandthedatafromthevirtual
memory

FULL
FULL

PASS
PASS

FULL

PASS

10

Createaninitialmemoryarray

FULL

PASS

11
12

Freeallmemoryresources
Allocatememoryinmemoryarrayandreturnapointer
totheallocatedmemory.
Deallocatememory.

FULL
FULL

PASS
PASS

FULL

PASS

14

Expandallocatedmemorysize,ifthereisntenough
roomtoexpand,freeitandallocatethenewdatatothe
endofthememoryarray.

FULL

PASS

15

Returnthetotalamountoffreememoryinmemory
array.
Printoutrawmemorycontentsashexandreturnthe
memorycontents
Defragmentmemoryarray.
Conductadeepcopy

FULL

PASS

FULL

PASS

FULL
FULL

PASS
PASS

2
3
4
5
6
7
8
9

13

16
17
18

DetailedSoftwareTesting

No

Test

ExpectedResults

Alloc/Realloc/Free
Testaddingdataatthefrontandbackof
virtualMemory

Testaddingdatainmemoryfragments
Testfreeingdata

Testthenullpointerreturnfromalloc
Dump,toString,<<
testthatitprintsoutallcharacters
correctly

testoperatoroverload

Foreachcase1.11.3:

a. allocated/freedsuccessfully,nobugs

1.4
a.NULLpointerwasreturned

3.1

deepcopyofamemorymanager

4.0

Avail

Forcase3.1
a. Deepcopywassuccessful.

4.1

Testthatitreturnsthecorrectvalue

1.0

1.1

1.2

1.3

1.4
2.0
2.1

2.2
3.0

10

Foreachcase2.12.2

a.functionscorrectlyoutputteddata

Forcase4.1

a.correctvaluewasreturned.

5. UserInstructions

OpenthefileMemManager.exe

OR
OpenfileMemManager.slninVisualStudio2010
Setupamemorymanagerinthemainfunctionwiththespecifiedsizeofmemory
thatyouwishtomanage,ordontspecifyitifyouwantittobesetto0
CallAlloc()withanintegerofthesizeofcharactersyouwanttoallocateinthe
virtualMemory
nowyoucanRealloc()orFree()tochangevaluesinthevirtualMemoryarray
YoucancallAvail()togettheamountoffreebytesleftinvirtualMemory
YoucancalltoString()togetapointertothestartingcharacterofvirtualMemory
Youcanconductadeepcopyofamemorymanagerusingthe=sign
ToprintoutthedatainhexandincharsyoucancallDump()oroperator<<

11

You might also like