On Monday 07 April 2003 02:39 am, Anders Johansson wrote:
On Monday 07 April 2003 07:08, Steven T. Hatton wrote:
I wasn't sure about the 'p + 1' part, but I did recall the part about incrementing by the 'size' of the object. My curiosity lies with the true meaning of 'size of the object'. This relates back to my awkward errant attempt to explain how memory is allocated for a class. I recall a frient of mine - who is pretty well versed in C - stated that the data in an array goes on the stack. That would mean 'p + 1' is referring to memory locations of the stack, and not the heap.
Jerry seems to know what he's talking about. I am operating on the assumption that these things are implementation details, and what Jerry is explaining is the 'recommended' implementation. Some of my questions are simply academic curiousity. It does help me to try and formulate these questions. It causes me to think about how to express what I'm doing in technically accurate terms.
I think you're looking too closely at details here. The C language doesn't define where things are stored, stack and heap are implementation details of the compiler, not part of the language.
I believe there are a few exceptions to that, but, in general you are correct. What I'm most interested in how to manage memory, and construct runtime object graphs.
If you want to learn the languages quickly, I would suggest you try to take a couple of steps back and focus on the bigger picture. I don't think it's pedagogically right to get bogged down in how gcc implements things.
I really don't want to spend too much time on this topic, but it has its importance. For example, in security, it's important to understand how, when, and where things are loaded into memory. And as I said, it helps me think about what I'm actually doing. That is, what *is* a runtime instance of a class? Where it goes, stack or heap, isn't so important, but the distinctions between pointer, variable, reference, automatic, static, etc., are.
Just a suggestion
I will agree that it's dangerous to try to exploit implementation details of a language which are not specified in defining document. I got bit hard by that when I tried to use an example my Professor gave of how to get the lenght of a string in Pascal by playing with the 0th element. It didn't work on a PC the same way it did on the Vax.
Anders
The question remains. How big is an object? What does sizeof really mean? Also, what's the lifetime of a member variable of derived type when created as a side effect of implicit (automatic?) instantiation in a function call variable declaration? STH