Il 17/08/2010 14.06, Black, Michael (IS) ha scritto: > I'm not an objective C expert (or even amateur) -- but it looks to me like > your use inside the function call is not setting anything in the object but > appears to be a cast. > > So your old success would completely depend on the behavior of the memory > allocator and garbage collector and how it reuses things. > > Isn't this: > sqlite3_bind_text(statement, 3, [self.lemmaRicerca > cStringUsingEncoding:NSUTF8StringEncoding], [self.lemmaRicerca > lengthOfBytesUsingEncoding:NSUTF8StringEncoding], SQLITE_STATIC); > > Saying "return self.lemmaRicerca as a cString..." and not "set > self.lemmaRicerca..." > So it would be out-of-scope outside the function call as you can't reference > the UTF8 format again, correct? > > >
That call returns a pointer (const char *) to a buffer containing the string representation in the requested encoding. In C++ it would be like writing: sqlite3_bind_text(statement, 3, this->lemmaRicerca->cStringUsingEncoding(NSUTF8StringEncoding), this->lemmaRicerca->lengthOfBytesUsingEncoding(NSUTF8StringEncoding), SQLITE_STATIC); My assumption was that the returned buffer would stay valid as long as the owner object (lemmaRicerca, a NSString object) is not deallocated. This app has garbage collecting enabled instead of manual memory management, however, and the documentation is not exactly clear on the behavior in this case. It appears that the collector frees some internal object that contains this buffer, so you end up with an invalid pointer by the time that SQLite executes the statement. Ironically I just checked the changes in Os X 10.6 and found this: "The methods -UTF8String and cStringUsingEncoding: are now declared as __strong, which means they return pointers that are safe to keep around when running with garbage collection." This would seem to suggest that *now* it should work and before it shouldn't have worked, but at this point I'll just leave it to SQLITE_TRANSIENT and waste a little more memory. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users