Re: Two arrays sharing the same adress space.
On Nov 17, 2008, at 10:01 AM, Scott Ribe wrote: Mounts is being used, but just not in the init function. You have declared it as a local variable. It *cannot* be used elsewhere. I suspect that you have also declared it as a member (attribute, property, whatever) and expect that you're assigning to that, but the local variable will shadow that, and so there's your problem. He may have that problem as well, but improper separation of alloc from init as explained earlier was definitely causing the symptom described. It's trivial to reproduce: NSMutableArray *mounts; NSMutableArray *bonjourServices; mounts = [[NSMutableArray alloc] init]; [mounts initWithContentsOfFile:@"NonexistentFile"]; // causes dealloc bonjourServices = [[NSMutableArray alloc] init]; // reuses dealloced memory NSLog(@"mounts = [%X], bonjourServices = [%X], equal? %d", mounts, bonjourServices, mounts == bonjourServices); This gives me: 2008-11-17 10:10:53.285 Scratch2[21580:10b] mounts = [1317D0], bonjourServices = [1317D0], equal? 1 --Andy ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
Thank you all, for taking the time to explain the workings this was very instructive and very apreciated!!! Thank you Sandro Noel. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
> Mounts is being used, but just not in the init function. You have declared it as a local variable. It *cannot* be used elsewhere. I suspect that you have also declared it as a member (attribute, property, whatever) and expect that you're assigning to that, but the local variable will shadow that, and so there's your problem. -- Scott Ribe [EMAIL PROTECTED] http://www.killerbytes.com/ (303) 722-0567 voice ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
On Nov 17, 2008, at 1:18 AM, Kyle Sluder wrote: On Mon, Nov 17, 2008 at 1:03 AM, Stephen J. Butler <[EMAIL PROTECTED]> wrote: 2) always use the value returned from an init* method. This isn't strictly necessary. If you need a singleton object that lives for the duration of your app, for example, there's no reason you can't just alloc/init one and let it go (unless, of course, you're using garbage collection, in which case it might matter). I can't imagine a likely scenario for this outside of misapplication of an idiom, but that doesn't make it illegal to ignore the return value of -init. I *think* Stephen meant we should use the value returned by the initializer as opposed to the value returned by alloc, not as opposed to ignoring it altogether. --Andy ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
On Nov 17, 2008, at 1:03 AM, Stephen J. Butler wrote: On Sun, Nov 16, 2008 at 11:52 PM, Sandro Noel <[EMAIL PROTECTED]> wrote: as it turns out. with the bug fixed the mounts array is left null because the file does not exist yet. so further in the program is i try to add to the array, nothing happens. and if i try "mounts = [[NSMutableArray alloc] init];" only the two arrays get the same pointer. Well, then what's happening is obvious. initWithContentsOfFile: fails because the file doesn't exist, so it performs cleanup (aka, call release) and returns null. Your next alloc then just happens to grab the same memory block. 1) never call the init* methods twice on the same object. 2) always use the value returned from an init* method. To elaborate, the reasons for these are based in the way init methods work: A) When init methods fail, by convention they release their memory and return nil so the caller knows they failed. B) When init methods succeed, they may return a different object than the original receiver. To spell this out: mounts = [[NSMutableArray alloc] init]; This allocates and initializes an empty NSMutableArray. Fine. [mounts initWithContentsOfFile:someFile]]; There are two possible cases here. A) If initWithContentsOfFile: fails, it releases the NSMutableArray, which in this case causes the memory to be deallocated, and returns nil. However, you're ignoring the return value, so mounts is now pointing to a deallocated block of memory. B) If initWithContentsOfFile: succeeds, your program *might* proceed just as you expect. However, it is *very* possible that it returns an object with a different address than mounts had before the call. So mounts *may* still point to a perfectly valid NSMutableArray, but not the one that contains your file contents. It's also conceivable that the original object gets corrupted by the double init (well, we could look at the source for NSMutableArray, but in the general case, there's no requirement that double inits always be safe). bonjourServices = [[NSMutableArray alloc]init]; What happened to you is that the memory formerly used by mounts happened to be reused to create bonjourServices. So now you had two variables that point to the same perfectly good NSMutableArray. Note that if bonjourServices was some other kind of object -- for example, a dictionary or a string -- you would have gotten a crash at some point when you tried to send a message to either mounts or bonjourServices that it didn't understand. The best way to follow Stephen's rules 1 and 2 is to always, *always* combine the alloc and init. Even though the following would have worked (assuming you added the check for a nil return)... mounts = [NSMutableArray alloc]; mounts = [mounts initWithContentsOfFile:someFile]]; ...it's just too easy to forget the assignment in the second line. Also, it would be easy to double-initialize by mistake. And finally, it would be jarring to any other Cocoa programmer reading your code, since the combined alloc/init is the established idiom. --Andy ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
On Mon, Nov 17, 2008 at 12:02 AM, Sandro Noel <[EMAIL PROTECTED]> wrote: > NSFileManager *fileManager; >fileManager = [NSFileManager defaultManager]; >if ( [fileManager fileExistsAtPath:[[self > applicationSupportFolder] stringByAppendingPathComponent:@"Bonjour > Mounter.plist"] isDirectory:NULL] ) { >mounts = [[NSMutableArray alloc] > initWithContentsOfFile:[[self applicationSupportFolder] > stringByAppendingPathComponent:@"Bonjour Mounter.plist"]]; > >} >else{ >mounts = [[NSMutableArray alloc] init]; >} I don't think this is the most robust solution. What happens if the file exists, but isn't readable by your user? What if the file is corrupt? mounts will end up nil . The better solution is: mounts = [[NSMutableArray alloc] initWithContentsOfFile:[[self applicationSupportFolder] stringByAppendingPathComponent:@"Bonjour Mounter.plist"]]; if (mounts == nil) mounts = [[NSMutableArray alloc] init]; ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
On Mon, Nov 17, 2008 at 1:03 AM, Stephen J. Butler <[EMAIL PROTECTED]> wrote: > 2) always use the value returned from an init* method. This isn't strictly necessary. If you need a singleton object that lives for the duration of your app, for example, there's no reason you can't just alloc/init one and let it go (unless, of course, you're using garbage collection, in which case it might matter). I can't imagine a likely scenario for this outside of misapplication of an idiom, but that doesn't make it illegal to ignore the return value of -init. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
On Sun, Nov 16, 2008 at 11:52 PM, Sandro Noel <[EMAIL PROTECTED]> wrote: > as it turns out. with the bug fixed the mounts array is left null because > the file does not exist yet. > so further in the program is i try to add to the array, nothing happens. > > and if i try "mounts = [[NSMutableArray alloc] init];" only the two arrays > get the same pointer. Well, then what's happening is obvious. initWithContentsOfFile: fails because the file doesn't exist, so it performs cleanup (aka, call release) and returns null. Your next alloc then just happens to grab the same memory block. So two things to learn from this: 1) never call the init* methods twice on the same object. 2) always use the value returned from an init* method. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
OK. the double initialization was the problem. the first init was giving me a pointer, and the second one was returning nothing because the file did not exist, and i guess the compiler was reusing it... the problem was fixed like this, sorry for the confusion guy's and thanks for the help. I guess it's past my bed time... NSFileManager *fileManager; fileManager = [NSFileManager defaultManager]; if ( [fileManager fileExistsAtPath:[[self applicationSupportFolder] stringByAppendingPathComponent:@"Bonjour Mounter.plist"] isDirectory:NULL] ) { mounts = [[NSMutableArray alloc] initWithContentsOfFile:[[self applicationSupportFolder] stringByAppendingPathComponent:@"Bonjour Mounter.plist"]]; } else{ mounts = [[NSMutableArray alloc] init]; } On 17-Nov-08, at 12:52 AM, Sandro Noel wrote: as it turns out. with the bug fixed the mounts array is left null because the file does not exist yet. so further in the program is i try to add to the array, nothing happens. and if i try "mounts = [[NSMutableArray alloc] init];" only the two arrays get the same pointer. transportTypes = [NSArray arrayWithObjects:@"afp",@"smb",@"cifs",@"nfs",nil]; mounts = [[NSMutableArray alloc] initWithContentsOfFile:[[self applicationSupportFolder] stringByAppendingPathComponent:@"Bonjour Mounter.plist"]]; bonjourServices = [[NSMutableArray alloc]init]; AFPScanner = [[BonjourScanner alloc]init]; SMBScanner = [[BonjourScanner alloc]init]; NFSScanner = [[BonjourScanner alloc]init]; AFPScanner.bonjourServices = bonjourServices; SMBScanner.bonjourServices = bonjourServices; NFSScanner.bonjourServices = bonjourServices; [AFPScanner searchForService:@"_afpovertcp._tcp." domain:nil]; [SMBScanner searchForService:@"_smb._tcp." domain:nil]; [NFSScanner searchForService:@"_nfs._tcp." domain:nil]; } return self; } On 17-Nov-08, at 12:47 AM, Charles Steinman wrote: Have you fixed the [mounts initWithContentsOfFile:...] bug and it still happens? Cheers, Chuck - Original Message From: Sandro Noel <[EMAIL PROTECTED]> To: Scott Ribe <[EMAIL PROTECTED]> Cc: cocoa-dev@lists.apple.com Sent: Sunday, November 16, 2008 9:16:15 PM Subject: Re: Two arrays sharing the same adress space. I'm actually checking here in this function. - (IBAction)mountSomeServers:(id)sender { NSDictionary *mountDictionary; mountDictionary = [NSDictionary dictionaryWithObjectsAndKeys: [server stringValue], ServerNameKey, [share stringValue], VolumeNameKey, [type title], TransportNameKey, @"", MountDirectoryKey, [user stringValue], UserNameKey, [password stringValue], PasswordKey, [NSNumber numberWithBool:YES], AsyncKey, NULL]; [mounts addObject:mountDictionary]; this is the only place where objects are being added to the mount array. I checked the init function and as soon as the bonjourServices array is initialized witch is after the mounts array it is assigned the same pointer as the mounts array, and from what i can deduce it's because the mounts array is empty at the time, because the file it is trying to load does not exist yet. I'm just guessing here, I've never encountered that kind of problem in 17 years of programing in any language. mind you i'm quite new to cocoa, but i did not face that problem in any of my other cocoa programs. Sandro Noel. On 17-Nov-08, at 12:04 AM, Scott Ribe wrote: This is a debug built, and I'm checking in the code where mounts is being assigned objects Which, if I recall correctly, is before bonjourServices is allocated. What do you think the problem is? --Scott Ribe [EMAIL PROTECTED] http://www.killerbytes.com/ (303) 722-0567 voice ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/acharlieblue%40yahoo.com This email sent to [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admin
Re: Two arrays sharing the same adress space.
as it turns out. with the bug fixed the mounts array is left null because the file does not exist yet. so further in the program is i try to add to the array, nothing happens. and if i try "mounts = [[NSMutableArray alloc] init];" only the two arrays get the same pointer. transportTypes = [NSArray arrayWithObjects:@"afp",@"smb",@"cifs",@"nfs",nil]; mounts = [[NSMutableArray alloc] initWithContentsOfFile:[[self applicationSupportFolder] stringByAppendingPathComponent:@"Bonjour Mounter.plist"]]; bonjourServices = [[NSMutableArray alloc]init]; AFPScanner = [[BonjourScanner alloc]init]; SMBScanner = [[BonjourScanner alloc]init]; NFSScanner = [[BonjourScanner alloc]init]; AFPScanner.bonjourServices = bonjourServices; SMBScanner.bonjourServices = bonjourServices; NFSScanner.bonjourServices = bonjourServices; [AFPScanner searchForService:@"_afpovertcp._tcp." domain:nil]; [SMBScanner searchForService:@"_smb._tcp." domain:nil]; [NFSScanner searchForService:@"_nfs._tcp." domain:nil]; } return self; } On 17-Nov-08, at 12:47 AM, Charles Steinman wrote: Have you fixed the [mounts initWithContentsOfFile:...] bug and it still happens? Cheers, Chuck - Original Message From: Sandro Noel <[EMAIL PROTECTED]> To: Scott Ribe <[EMAIL PROTECTED]> Cc: cocoa-dev@lists.apple.com Sent: Sunday, November 16, 2008 9:16:15 PM Subject: Re: Two arrays sharing the same adress space. I'm actually checking here in this function. - (IBAction)mountSomeServers:(id)sender { NSDictionary *mountDictionary; mountDictionary = [NSDictionary dictionaryWithObjectsAndKeys: [server stringValue], ServerNameKey, [share stringValue], VolumeNameKey, [type title], TransportNameKey, @"", MountDirectoryKey, [user stringValue], UserNameKey, [password stringValue], PasswordKey, [NSNumber numberWithBool:YES], AsyncKey, NULL]; [mounts addObject:mountDictionary]; this is the only place where objects are being added to the mount array. I checked the init function and as soon as the bonjourServices array is initialized witch is after the mounts array it is assigned the same pointer as the mounts array, and from what i can deduce it's because the mounts array is empty at the time, because the file it is trying to load does not exist yet. I'm just guessing here, I've never encountered that kind of problem in 17 years of programing in any language. mind you i'm quite new to cocoa, but i did not face that problem in any of my other cocoa programs. Sandro Noel. On 17-Nov-08, at 12:04 AM, Scott Ribe wrote: This is a debug built, and I'm checking in the code where mounts is being assigned objects Which, if I recall correctly, is before bonjourServices is allocated. What do you think the problem is? --Scott Ribe [EMAIL PROTECTED] http://www.killerbytes.com/ (303) 722-0567 voice ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/acharlieblue%40yahoo.com This email sent to [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
Have you fixed the [mounts initWithContentsOfFile:...] bug and it still happens? Cheers, Chuck - Original Message > From: Sandro Noel <[EMAIL PROTECTED]> > To: Scott Ribe <[EMAIL PROTECTED]> > Cc: cocoa-dev@lists.apple.com > Sent: Sunday, November 16, 2008 9:16:15 PM > Subject: Re: Two arrays sharing the same adress space. > > I'm actually checking here in this function. > > - (IBAction)mountSomeServers:(id)sender > { > > NSDictionary *mountDictionary; > > mountDictionary = [NSDictionary dictionaryWithObjectsAndKeys: >[server stringValue], ServerNameKey, >[share stringValue], VolumeNameKey, >[type title], TransportNameKey, >@"", MountDirectoryKey, >[user stringValue], UserNameKey, >[password stringValue], PasswordKey, >[NSNumber numberWithBool:YES], AsyncKey, NULL]; > [mounts addObject:mountDictionary]; > > this is the only place where objects are being added to the mount array. > > I checked the init function and as soon as the bonjourServices array is > initialized witch is after the mounts array > it is assigned the same pointer as the mounts array, and from what i can > deduce > it's because the mounts array is empty > at the time, because the file it is trying to load does not exist yet. > > I'm just guessing here, I've never encountered that kind of problem in 17 > years > of programing in any language. > mind you i'm quite new to cocoa, but i did not face that problem in any of my > other cocoa programs. > > Sandro Noel. > > On 17-Nov-08, at 12:04 AM, Scott Ribe wrote: > > >> This is a debug built, and I'm checking in the code where mounts is > >> being assigned objects > > > > Which, if I recall correctly, is before bonjourServices is allocated. What > > do you think the problem is? > > > > --Scott Ribe > > [EMAIL PROTECTED] > > http://www.killerbytes.com/ > > (303) 722-0567 voice > > > > > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > http://lists.apple.com/mailman/options/cocoa-dev/acharlieblue%40yahoo.com > > This email sent to [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
I'm actually checking here in this function. - (IBAction)mountSomeServers:(id)sender { NSDictionary *mountDictionary; mountDictionary = [NSDictionary dictionaryWithObjectsAndKeys: [server stringValue], ServerNameKey, [share stringValue], VolumeNameKey, [type title], TransportNameKey, @"", MountDirectoryKey, [user stringValue], UserNameKey, [password stringValue], PasswordKey, [NSNumber numberWithBool:YES], AsyncKey, NULL]; [mounts addObject:mountDictionary]; this is the only place where objects are being added to the mount array. I checked the init function and as soon as the bonjourServices array is initialized witch is after the mounts array it is assigned the same pointer as the mounts array, and from what i can deduce it's because the mounts array is empty at the time, because the file it is trying to load does not exist yet. I'm just guessing here, I've never encountered that kind of problem in 17 years of programing in any language. mind you i'm quite new to cocoa, but i did not face that problem in any of my other cocoa programs. Sandro Noel. On 17-Nov-08, at 12:04 AM, Scott Ribe wrote: This is a debug built, and I'm checking in the code where mounts is being assigned objects Which, if I recall correctly, is before bonjourServices is allocated. What do you think the problem is? -- Scott Ribe [EMAIL PROTECTED] http://www.killerbytes.com/ (303) 722-0567 voice ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
> This is a debug built, and I'm checking in the code where mounts is > being assigned objects Which, if I recall correctly, is before bonjourServices is allocated. What do you think the problem is? -- Scott Ribe [EMAIL PROTECTED] http://www.killerbytes.com/ (303) 722-0567 voice ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
Forgot to answer the first question. This is a debug built, and I'm checking in the code where mounts is being assigned objects I have not enabled any optimization that I know of ... Sandro Noel. On 16-Nov-08, at 11:37 PM, Scott Ribe wrote: At what point in the code are you checking? Is this a release build, or a debug build in which you've gone & enabled some optimizations? In the code you posted mounts is init'd (twice actually, which is unecessary), then never used. It's perfectly possible that the two variables mounts & bonjourServices will be stored in the same register-- depending on compiler settings. In other words, the two arrays would certainly have different addresses. But since you're not referring to mounts after it's initialized, the space where the pointer to mounts is stored can be reused to store the different pointer to bonjourServices. Step it line by line, and watch the values of those variables. Or actually do something with mounts later in the method. Or get rid of mounts if you're not going to use it. -- Scott Ribe [EMAIL PROTECTED] http://www.killerbytes.com/ (303) 722-0567 voice ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
Scott. thank you for your explanation. Mounts is being used, but just not in the init function. it is being used later in the code. that is why i was geting confused because the 2 arrays, are not meant to hold the same type of data. and right now, they contain mixed data type. witch makes my other functions crash. On 16-Nov-08, at 11:37 PM, Scott Ribe wrote: At what point in the code are you checking? Is this a release build, or a debug build in which you've gone & enabled some optimizations? In the code you posted mounts is init'd (twice actually, which is unecessary), then never used. It's perfectly possible that the two variables mounts & bonjourServices will be stored in the same register-- depending on compiler settings. In other words, the two arrays would certainly have different addresses. But since you're not referring to mounts after it's initialized, the space where the pointer to mounts is stored can be reused to store the different pointer to bonjourServices. Step it line by line, and watch the values of those variables. Or actually do something with mounts later in the method. Or get rid of mounts if you're not going to use it. -- Scott Ribe [EMAIL PROTECTED] http://www.killerbytes.com/ (303) 722-0567 voice ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
At what point in the code are you checking? Is this a release build, or a debug build in which you've gone & enabled some optimizations? In the code you posted mounts is init'd (twice actually, which is unecessary), then never used. It's perfectly possible that the two variables mounts & bonjourServices will be stored in the same register--depending on compiler settings. In other words, the two arrays would certainly have different addresses. But since you're not referring to mounts after it's initialized, the space where the pointer to mounts is stored can be reused to store the different pointer to bonjourServices. Step it line by line, and watch the values of those variables. Or actually do something with mounts later in the method. Or get rid of mounts if you're not going to use it. -- Scott Ribe [EMAIL PROTECTED] http://www.killerbytes.com/ (303) 722-0567 voice ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
On Nov 16, 2008, at 8:22 PM, Sandro Noel wrote: mounts = [[NSMutableArray alloc] init]; [mounts initWithContentsOfFile:[[self applicationSupportFolder] stringByAppendingPathComponent:@"Bonjour Mounter.plist"]]; You are initializing "mounts" twice, and you're also throwing away what the second initialization returns (which may be different from the first because init can cause new objects to be returned). I suppose your code should be: mounts = [[NSMutableArray alloc] initWithContentsOfFile:[[self applicationSupportFolder] stringByAppendingPathComponent:@"Bonjour Mounter.plist"]]; Regards Markus -- __ Markus Spoettl smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Two arrays sharing the same adress space.
I just declared a third NSMutableArray to see if that one would have a different pointer, and well it had the same pointer somehow... what is this ? is it some type of setting ? Sandro Noel. On 16-Nov-08, at 11:22 PM, Sandro Noel wrote: Greetings. I'm having a weird behaviour, i have 2 arrays declared in the same controller, and for some reason they both share the same memory space. well actually in debug they share the same pointer, witch is not something I asked for. the bonjourservices and the mounts array's are the ones geting the same pointer. here is my code. NSMutableArray *bonjourServices; NSMutableArray *mounts; transportTypes = [NSArray arrayWithObjects:@"afp",@"smb",@"cifs",@"nfs",nil]; mounts = [[NSMutableArray alloc] init]; [mounts initWithContentsOfFile:[[self applicationSupportFolder] stringByAppendingPathComponent:@"Bonjour Mounter.plist"]]; // the bonjourScanner sends a notification when the content of the passed array is modified, we will pick it up here. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bonjourServiceNotigficationUpdate) name:SERVICE_ADD_REMOVE_NOTIFICATION object:nil]; bonjourServices = [[NSMutableArray alloc]init]; AFPScanner = [[BonjourScanner alloc]init]; SMBScanner = [[BonjourScanner alloc]init]; NFSScanner = [[BonjourScanner alloc]init]; AFPScanner.bonjourServices = bonjourServices; SMBScanner.bonjourServices = bonjourServices; NFSScanner.bonjourServices = bonjourServices; [AFPScanner searchForService:@"_afpovertcp._tcp." domain:nil]; [SMBScanner searchForService:@"_smb._tcp." domain:nil]; [NFSScanner searchForService:@"_nfs._tcp." domain:nil]; did anyone ever have that kind of problem ? i'm a little puzzled, thank you ... Sandro Noel. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/sandro.noel%40mac.com This email sent to [EMAIL PROTECTED] ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]