Re: memory trampling
On Oct 20, 12:03 pm, Zeppe
<ze...@remove.all.this.long.comment.yahoo.it> wrote:
joshuajnoblewrote:
That causes a EXEC_BAD_ACCESS when the thread actually does its
processing because the memory is getting trampled and I GDB can't
reconstrcut the frame:
previous frame inner to this frame (corrupt stack?)
Now, I'm not super savvy on what exacty the thread does with that
memory, but I've played around with it a lot outside of my little
wrapper library scheme and it works fine, so the problem is in my
implementation.
You say that without "wrapping" the creation of obj within the WrapperA
constructor and calling the delegate everything works fine. Since I
cannot see any obvious error in that code, I try to guess: may it be a
problem of static initialisation order? When do you call the Wrapper::ini=
t?
And, if your Delegate is built at the program initialisation, are you
sure that the thread object, if not built within the delegate, is
already there?
Best wishes,
Zeppe
I threw together a quick test here, I'm thinking my problem is in what
I'm doing with the static pointer (perhaps). Here's my Singleton:
#ifndef SINGLETON
#define SINGLETON
class SingletonImpl
{
public:
static SingletonImpl* getInst();
int val1;
char* val2[5];
protected:
static SingletonImpl* inst;
SingletonImpl();
};
#endif
SingletonImpl::SingletonImpl(){
val1 = 1;
val2 = "abcdefghijklmn";
}
SingletonImpl* SingletonImpl::getInst(){
if(inst == 0) {
inst = new SingletonImpl();
}
return inst;
}
And then I have some objects that I need to have access the singleton
in their constructors:
#include "TestObjs.h"
TestObjs::TestObjs(char* ch){
c = ch;
SingletonImpl::getInst()->val2[0] = c;
}
class TestObjs {
public:
TestObjs(char* ch);
char* c;
};
And then my main:
int main (int argc, char * const argv[]) {
char* c = "ghu";
TestObjs t = TestObjs(c);
char* c3 = "3333333";
TestObjs t2 = TestObjs(c3);
return 0;
}
And this blows up...I realize this is a pretty rudimentary question
and not really on par with the normal level of discussion here so
thanks in advance for any help and your patience :)