gnustep-dev
[Top][All Lists]
Advanced

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

Solaris problem rallocing arrays


From: Adam Fedor
Subject: Solaris problem rallocing arrays
Date: Tue, 20 Mar 2001 10:13:46 -0700

I'm getting the oddest behaviour on Solaris (2.6) machines in
NSProcessInfo(_gnu_process_args). The code is essentially

    NSMutableArray      *keys = [NSMutableArray new];

    for {each environment variable...}
       [keys addObject: [NSString stringWithCString: {some C string}]];

The default initializer creates an array with capacity 1, so there is a
lot of realloc'ing the array early on. On the third realloc
(capacity==4), the actual CONTENTS of the first three values of the
array change! As if,

a[0] = 1; a[1] = 2; a[2] = 3; a[3] = 4

becomes

a[0] = 45345; a[1] = 0; a[2] = 0; a[3] = 4;

simply due to a realloc of a (in fact a[0] takes on the value of &a[4]).
Does anyone have any ideas what would cause this? Solaris has
problems with word alignment, but I don't see that happening here.
Just changing  the initialization to 

    NSMutableArray      *keys = [[NSMutableArray alloc]
initWithCapacity: 8];

fixes the problem
-- 
Adam Fedor, Digital Optics            | Fudd's law of opposition: Push
address@hidden  http://www.doc.com     | something hard enough, and it 
address@hidden  http://www.gnustep.org | will fall over.



reply via email to

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