Re: memory
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Sat, 20 Sep 2008 01:05:54 -0400
Jon Slaughter wrote:
"Bill Cunningham" <nospam@xxxxxxxxxxxxx> wrote in message
In C I have never really used malloc to alloc memory from theObviously?
heap. Now when using C's data types you are using the stack if
I am correct. In programming requirements are there times when
you want memory allocated from either parts of memory?
int mem[100]; 100 ints from stack
int *pi=malloc(100); 100 ints from heap
Suppose you want to return an array from a method? If the method
allocates the array on the stack then it won't be valid after
the method returns.
Don't confuse him. Bill uses C, which doesn't have C++ methods.
In addition "pi = malloc(100);" returns storage for 100 chars, not
ints. To get 100 items use the normal malloc call of "pi =
malloc(100 * sizeof *pi);", which will follow the type of pi.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
.
- References:
- memory
- From: Bill Cunningham
- Re: memory
- From: Jon Slaughter
- memory
- Prev by Date: Download free eBooks!!!
- Next by Date: Re: memory
- Previous by thread: Re: memory
- Next by thread: Re: memory
- Index(es):
Relevant Pages
|