answersLogoWhite

0

The new operator returns a pointer to the memory allocated to an object, or returns NULL if the memory cannot be allocated. This isn't an error as such, it simply means there isn't a large enough block of free memory available to meet the allocation. There may well be more than enough unused memory available, but the memory must be allocated as a single, contiguous block. Modern operating systems use hard-disk space to provide more memory than physically exists in the system (virtual memory), however with a 32-bit system there is an upper limit of 4GB (which includes video memory), of which only 2GB is available to applications. Thus if the user has a lot of programs consuming a lot of memory then it may not be possible to free up enough physical RAM to meet an allocation. Hence the need to check if a returned pointer is non-NULL before attempting to access the memory it points to. On a 64-bit system this is less of a problem because there's effectively unlimited memory (the only limit being free hard-drive space), but even then you must still check a pointer is non-NULL before indirectly accessing the memory it points to.

User Avatar

Wiki User

11y ago

Still curious? Ask our experts.

Chat with our AI personalities

EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra
RossRoss
Every question is just a happy little opportunity.
Chat with Ross
CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach

Add your answer:

Earn +20 pts
Q: Why do you get memory access errors with new operator?
Write your answer...
Submit
Still have questions?
magnify glass
imp