[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

How can I catch the memory error...

I'm writing a application which need to resize(or renew) a imge buffer's size by custom. So I must adjust
whether my app could provide the enough space to do this.
But in fact, after using whether SetHandleSize() or NewHandle(), I call the MemError() to get the error number, its value is always no changed,
How can I catch the error, or find another way?
0
bhzhao
Asked:
bhzhao
  • 2
1 Solution
 
boonstraCommented:
Check the result that NewHandle returns.  If it returns NIL, the system was unable to allocate the requested amount of memory.  You won't find out about that from MemError().

SethandleSize() should return memFullErr (-108) if there is not enough memory.

What makes you think the memory allocation is failing?  How much memory are you (re)allocating?  What is the heap size of your application?  How much memory does your machine have?
0
 
bhzhaoAuthor Commented:
Thanks for your help. I also want to ask How I could know how many memory my app need at least, i.e how may empty memory should I left for my app. So I can limit the buffer size (re)allocated.

After using SetHandleSize(), it seemed it was success, but the application would crash when exit this procedure. I think the most possibale reason is that this block had covered parts of the stack of this app.
0
 
boonstraCommented:
If you are using CodeWarrior, I would recommend investigating ZoneRanger to analyze your memory usage.  One way to estimate your app memory usage without the buffer increase is to profile it without that code, and see how much memory it takes.

I don't think SetHandleSize would have succeeded if your heap collided with the stack.  More likely you are getting the memory you allocate, but overwriting what you asked for.  Make sure, for example, that you aren't allocating N bytes and then writing out N longs.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now