Discussion:
A3q2 again
(too old to reply)
kun qian
2011-06-12 21:56:38 UTC
Permalink
from the assignment it says "...Otherwise, push the file name on the
stack, open it, and begin
processing it. ..." I don't see how processOneFIle would not need a
push routine that allocated memory. Am I misunderstanding something?
Tony Cui
2011-06-13 00:01:10 UTC
Permalink
Post by kun qian
from the assignment it says "...Otherwise, push the file name on the
stack, open it, and begin
processing it. ..." I don't see how processOneFIle would not need a
push routine that allocated memory. Am I misunderstanding something?
Dynamically allocated essentially means allocated on the heap. You can
allocate memory in processOneFile as long as you make sure it's not on
the heap.
Terry Anderson
2011-06-13 00:10:20 UTC
Permalink
In order for you to be able to push a Node structure (representing a
filename) onto the stack described in the assignment, you're right that
you would need space in memory in order to store this Node structure. But
what the restriction states is that the Node cannot be placed on the heap
(i.e., the use of new, malloc, or similar in the processOneFile routine is
forbidden).
--
Terry Anderson
CS 246 Instructor
Post by kun qian
from the assignment it says "...Otherwise, push the file name on the
stack, open it, and begin
processing it. ..." I don't see how processOneFIle would not need a
push routine that allocated memory. Am I misunderstanding something?
kun qian
2011-06-13 04:14:46 UTC
Permalink
Post by Terry Anderson
In order for you to be able to push a Node structure (representing a
filename) onto the stack described in the assignment, you're right that
you would need space in memory in order to store this Node structure.  But
what the restriction states is that the Node cannot be placed on the heap
(i.e., the use of new, malloc, or similar in the processOneFile routine is
forbidden).
--
Terry Anderson
CS 246 Instructor
Post by kun qian
from the assignment it says "...Otherwise, push the file name on the
stack, open it, and begin
processing it. ..." I don't see how processOneFIle would not need a
push routine that allocated memory. Am I misunderstanding something?
Doesn't new Node use stack for memory allocation?
John Altenmueller
2011-06-13 12:43:26 UTC
Permalink
Post by kun qian
Doesn't new Node use stack for memory allocation?
No. For example,

Node* blah = new Node; // allocates memory on the heap

Hint: it's not very difficult to allocate memory on the stack.
kun qian
2011-06-13 19:00:55 UTC
Permalink
Post by John Altenmueller
Post by kun qian
Doesn't new Node use stack for memory allocation?
No. For example,
Node* blah = new Node; // allocates memory on the heap
Hint: it's not very difficult to allocate memory on the stack.
This seem more like a knowledge based question than a puzzle. Would
you mind pointing me to the right direction?

kun qian
2011-06-13 04:22:59 UTC
Permalink
Post by Terry Anderson
In order for you to be able to push a Node structure (representing a
filename) onto the stack described in the assignment, you're right that
you would need space in memory in order to store this Node structure.  But
what the restriction states is that the Node cannot be placed on the heap
(i.e., the use of new, malloc, or similar in the processOneFile routine is
forbidden).
--
Terry Anderson
CS 246 Instructor
Post by kun qian
from the assignment it says "...Otherwise, push the file name on the
stack, open it, and begin
processing it. ..." I don't see how processOneFIle would not need a
push routine that allocated memory. Am I misunderstanding something?
Has it been mention in class how to allocate memory without using heap?
kun qian
2011-06-13 04:42:37 UTC
Permalink
Post by kun qian
Post by Terry Anderson
In order for you to be able to push a Node structure (representing a
filename) onto the stack described in the assignment, you're right that
you would need space in memory in order to store this Node structure.  But
what the restriction states is that the Node cannot be placed on the heap
(i.e., the use of new, malloc, or similar in the processOneFile routine is
forbidden).
--
Terry Anderson
CS 246 Instructor
Post by kun qian
from the assignment it says "...Otherwise, push the file name on the
stack, open it, and begin
processing it. ..." I don't see how processOneFIle would not need a
push routine that allocated memory. Am I misunderstanding something?
Has it been mention in class how to allocate memory without using heap?
What memory allocation does an array use?
Loading...