swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Swarm-Support] I have the strangest seg fault (ever)!


From: Marcus G. Daniels
Subject: Re: [Swarm-Support] I have the strangest seg fault (ever)!
Date: Sat, 16 Apr 2005 01:14:36 -0600
User-agent: Mozilla Thunderbird 0.9 (Windows/20041103)

Paul Johnson wrote:

Do you think it would be better if the EZGraph made a copy of the color array? Rather than just keeping a pointer to some memory?

Nah, I think that kind of usage is just something one has to be careful about in C. A single literal string like "foobar" will persist in memory and has a single address in a program no matter what. The problem in your case wasn't the literals, it was the pointers to them. That was being initialized on the stack for the method, and then the stack was unwound on exit, leaving a pointer to the stack, but one that was no longer valid. Like pointing to spot in the ocean, but without the boat. Using a type of `static' moves that memory from the stack to the permanent heap, and using an ivar moves it to the temporary heap (typically same area of the memory but can be recycled); both can be used to make that array of pointers valid across functions or method calls.
reply via email to

[Prev in Thread] Current Thread [Next in Thread]