Thursday, February 25, 2010

Memory Allocation

to Allocate memory is an easy process but to allocate memory properly is a tricky part and it helps make you're program more efficient.
So how to allocate memory properly :
1- create a pointer to use it to pint at the memory.
2- Allocate memory and set it or assign it to what you need .
3- Use the Memory in you're program.
4- De allocate the memory allocated.
that seems pretty forward and easy but what really hard is when you find the memory is too big or too small for your data so you create another array ! wrong that causes a memory leak. The programmer needs to reallocate memory.
How to reallocate memory :
1-Create temporary pointer
2- allocate the size of memory you need to use .
3- copy old data to new array .
4- de allocate old memory.
5- use the original pointer point to the new memory.
6- Don't delete temporary pointer it's gonna be deleted automatically.
The point of doing all of these is keeping your program out of pugs.

Monday, February 8, 2010

String Vs Charecters

I had a code thet used " " to display a single space but it gave me a crazy answer like it showed <. I didn't know what to do so I asked freind
this is the code : http://pastebin.ca/1790805
this is why it showed < :
well i see one problem
you probably want to use ' ' not " "
" " is for a string and will add a null byte to the end...i dont know if that could be causing the problem or not
it should be ' ' not " "
" " is for strings, ' ' is for characters
so I know now what was my problem and my code is
working nicely now thanks tdot