Couple of issues...

Member
Posts: 215
Joined: 2008.06
Post: #1
I currently have two major issues:

After some testing, my program has crashed a few times with a SIGSEGV error. According to Wikipedia, this is a memory address error. Does that mean I ran out of memory, or what?

Second, I've been curious about NSAutoreleasePools. I've seen them used (without good commenting) and I'm wondering what the proper use for these is? Are they micro-garbage-collection in the sense that they keep track of pointers and deallocate objects I'm not using?

Thanks!

Mac users swear by their computers, PC users swear at their computers. ~Unknown

iSayz
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
SIGSEGV is usually (but not always) caused by dereferencing a NULL pointer. eg.

Code:
int *a = NULL;
*a = 3;

The backtrace from the crash will almost always show you exactly where you're crashing, and it is almost always obvious why.

Unless you have a long-running method (like a thread, perhaps, or a very expensive user action) you'll never need to create an NSAutoreleasePool. If you don't understand them, ignore them, would be my advice Wink
Quote this message in a reply
Member
Posts: 215
Joined: 2008.06
Post: #3
OneSadCookie Wrote:SIGSEGV is usually (but not always) caused by dereferencing a NULL pointer. eg.

Code:
int *a = NULL;
*a = 3;

The backtrace from the crash will almost always show you exactly where you're crashing, and it is almost always obvious why.

Unless you have a long-running method (like a thread, perhaps, or a very expensive user action) you'll never need to create an NSAutoreleasePool. If you don't understand them, ignore them, would be my advice Wink

Well, at this point I DO have another thread. Could it be that my physics thread is using the same object as my rendering engine at the same time? That wouldn't cause any kind of issue as far as I can see, because the render engine has nothing to do with the data that my physics engine needs. How can I improve my engines' thread safety, if that is the case? Which brings me around to another question:

As far as I understand it from the example code and docs, using an NSOperationQueue creates a new thread in which to execute the given code. I want to update my physics engine in a separate thread every time, so it seems that pushing it onto a NSOperationQueue is probably inefficient. Is there a way I can reserve a thread for my physics engine, and my physics engine ONLY?

Mac users swear by their computers, PC users swear at their computers. ~Unknown

iSayz
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
NSOperationQueue keeps a pool of threads and assigns each operation to a free thread. It tracks things like the number of CPUs in the machine to know how many concurrent tasks are best run at once. If you can use NSOperationQueue, you probably should. If you can't, you can always use NSThread directly.

That said, threaded programming is *not* for beginners or for the faint-of-heart. If one is not *very* *very* careful, one can easily end up with impossible-to-reproduce crashes, deadlocks or race conditions. To be blunt, if you can't debug a segfault, you don't stand a shit show in hell of writing working threaded code. If you don't *need* to go there, don't go there... and I very much doubt you need to go there.
Quote this message in a reply
Member
Posts: 254
Joined: 2005.10
Post: #5
It's been a while since I saw a SIGSEGV, but if I remember correctly SIGSEGV can also be thrown when you try to use some memory you have freed. That kind of situation usually occurs in C++. However, in Objective-C you can send messages to null without a problem and I think that also applies to a released object, so you shouldn't see a SIGSEGV from that.

As far as autorelease pools go, remember that Cocoa provides a run loop which waits for user input then fires an event so your code can handle it. After your code is done the run loop will release any objects in the autorelease pool, then go back to waiting for user input.
Quote this message in a reply
Post Reply