+ 2
Am I being too literal?
For my part of the assignment about tracking memory allocation I have done this: int Integer; int* PI; int main() { PI = & Integer; cout << sizeof(Integer)<<endl; cout<<PI; return 0; } Surely they want more than this. Especially as they don't just want text output?
14 Respuestas
+ 7
They probably want you to look at new and delete as well
http://www.cplusplus.com/doc/tutorial/dynamic/
also, globals are not great to use.
see this copy of your code I have modified to make them local
https://code.sololearn.com/cpoNYuFs9y3Q/?ref=app
+ 7
https://www.ibm.com/developerworks/aix/tutorials/au-memorymanager/index.html
+ 6
talk about throwing you in the deep end 😆
+ 6
no worries!
+ 4
The address pointers hold are all integers. You specify the type the address points to by proceeding the type with *. So for char it's char*
+ 4
I can't see your assignment, but your code works here (keeping SoloLearn's template includes).
I verified this is working by setting a value:
int Integer=99;
and dereferencing the pointer:
cout<<*PI;
+ 4
@Richard Appleton ... Yeah, I saw your interface/implementation Q&A, started an analogy to a grocery store / inventory vs shopping, then realized a visual code would be better.
In the meantime you had lots of help so that was nice :)
+ 4
Seriously though, this looks like fun. I'll be happy to practice helping without answering if the situation warrants.
+ 2
Thanks Kirk. My full assignment is on my post called "More Newbie Questions" but this part of it is to write a code which tracks and reports memory allocations.
+ 2
Yes. everybody on here is very patient.
+ 2
That's brilliant.. Thanks, @Jay! :-)
+ 1
Ok... So I have clarification of what they actually want:
You should be aiming to do the following:
· Take control of memory allocation and deallocation via some kind of management class or other implementation
Then
· Track and report any memory leaks (Any memory which is allocated should be deallocated, if it is not deallocated the memory is still in use and can continue to eat into system resources. This is a memory leak.)
· Implement a method to deal with memory fragmentation at runtime. Fragmentation occurs when old memory is deallocated and new memory is allocated.
Consider this situation:
You allocate three blocks of memory to separate objects.
You deallocate the second block of memory as it is no longer useful. Leaving a block of free memory between the other two blocks of memory.
When you allocate new memory you reuse this free block of memory, however, the new object you allocate memory to takes up fractionally less memory and there is a small amount of free memory available between the second block and the third block.
This block of free memory is too small for anything to be allocated to it.
If this memory fragmentation happens continually without any kind of countermeasure, you will eventually run out of free memory while having lots of free memory!
+ 1
Haha. Yeah. This is going to be a google job when I get home, just to find out what it means!! :-D
0
Are all pointers not integers? how do I set a pointer to the memory address of a character?