|
Smith, Nelson wrote:
6.) Where is the information regarding how much memory has beenallocatedto a pointer stored? Is there an API to get at it? Maybe if I knewthis, Iwould be able to determine the answers to the other questions above.Basically, you manage that information yourself. It is up to you to keep track of which pointers point to valid storage, and how much storage is available for each pointer. Cheers! Hans[Smith, Nelson] How does the system know when you are out of bounds?
There are two issues. First, if you go beyond the bounds of the space, you get a machine exception. But the other issue is trickier. If you allocate, say, 100 bytes of storage, you could easily add 100 to the basing pointer and point to the memory just beyond what you've allocated. This could very well be within the data space, but of course, might contain something that you'd better not touch. Unlike the first case, the machine isn't going to tell you that you've screwed up something, and you might not know something is wrong until much later on in your program. The bottom line is this: Using dynamic storage allocation and pointers is tricky, and should be used with the utmost of care if it can't be at all avoided. Cheers! Hans
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.