Re: BOOL array

2008-09-15 Thread Ken Thomases

On Sep 15, 2008, at 5:16 PM, Alex Reynolds wrote:


I also wanted to learn a bit about Objective-C++.

What are the issues that involve exceptions? I find that  
NSExceptions I have in my larger application still work when I poke  
those.


In the 32-bit runtime, Objective-C exceptions and C++ exceptions use  
incompatible mechanisms.  Objective-C exceptions do not unwind the  
stack and invoke destructors of all automatic variables between the  
throw and the catch.  C++ exceptions, while unwinding the stack, don't  
invoke Objective-C @finally clauses.  Objective-C exceptions can't be  
caught by C++ catch clauses, and vice versa.


In the 64-bit runtime, these limitations have been removed: http://developer.apple.com/releasenotes/Cocoa/RN-ObjectiveC/index.html#/ 
/apple_ref/doc/uid/TP40004309-DontLinkElementID_11


Cheers,
Ken

___

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: BOOL array

2008-09-15 Thread Alex Reynolds
BOOL vs. bool aside (as well as a couple methods that return NSString* 
and throw NSException) I wanted to take a stab at making this particular 
class more portable.


If I wrote it closer to the C++ STL spec, I could more easily use it in 
other contexts while writing my larger application in Cocoa (well, Cocoa 
Touch, but I guess I can't really say that).


I also wanted to learn a bit about Objective-C++.

What are the issues that involve exceptions? I find that NSExceptions I 
have in my larger application still work when I poke those.


I did set up something like:

--
#include 

...
try {
	std::vector *myTestVector = new std::vector(numOfElements, 
emptyElement);

} catch(std::bad_alloc &exc) {
NSLog(@"%@", exc.what());
}
...
delete myTestVector;
--

but I haven't pressure tested it with, say, 100 million elements to see 
if it cracks.


I do run into lots of compilation errors if I don't rename all of my 
Cocoa classes to *.mm. But otherwise, the application compiles fine and 
I seem to be able to use all the ObjC syntax I'm used to.


I apologize if these are dumb questions. I appreciate all the advice.

-Alex

Kyle Sluder wrote:

On Mon, Sep 15, 2008 at 5:43 PM, Alex Reynolds <[EMAIL PROTECTED]> wrote:

Are there any downsides to creating Cocoa-based applications in Objective
C++?


If you're switching to Objective-C++ just to get std::vector, I would
strongly suggest you reconsider.  There are plenty of issues regarding
ObjC++ in the legacy runtime, particularly involving exceptions.  Is
there a reason you chose to make such a radical change instead of just
using CFBitVector?

--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: BOOL array

2008-09-15 Thread Kyle Sluder
On Mon, Sep 15, 2008 at 5:43 PM, Alex Reynolds <[EMAIL PROTECTED]> wrote:
> Are there any downsides to creating Cocoa-based applications in Objective
> C++?

If you're switching to Objective-C++ just to get std::vector, I would
strongly suggest you reconsider.  There are plenty of issues regarding
ObjC++ in the legacy runtime, particularly involving exceptions.  Is
there a reason you chose to make such a radical change instead of just
using CFBitVector?

--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: BOOL array

2008-09-15 Thread Ken Thomases

On Sep 15, 2008, at 4:43 PM, Alex Reynolds wrote:

Is there a difference in the underlying storage between vector  
and

vector?


Yes!  std::vector is a class template.  There's a generic  
implementation provided that works with any type (within certain  
constraints), but there's a specialization for the 'bool' case.  You  
only get ~1 bit for bit with the specialization, i.e. vector.


Given that BOOL is typedef'ed to signed char, vector uses the  
same storage as vector, about 1 byte per element.


Cheers,
Ken
___

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: BOOL array

2008-09-15 Thread Clark Cox
On Mon, Sep 15, 2008 at 2:43 PM, Alex Reynolds <[EMAIL PROTECTED]> wrote:
>>
>> Of course there's always std::vector< bool > ;-) usually at 1 bit per
>> bit...
>>
>> --
>> Scott Ribe
>> [EMAIL PROTECTED]
>> http://www.killerbytes.com/
>> (303) 722-0567 voice
>
>
> Thanks for the tip. So I ended up going the route of making my .m files into
> .mm files, and using std::vector< vector > to store vectors of
> vector's.
>
> I found that iterator and const_iterator did not work on vector or
> vector objects. I grabbed vector.size() in order to loop over the
> vector.
>
> Is there a difference in the underlying storage between vector and
> vector? Is it really a vector of single bits or a vector of larger
> data?

vector will use 1 bit per element, vector will use 8 bits
per element.

>
> Are there any downsides to creating Cocoa-based applications in Objective
> C++?
>
> Thanks,
> Alex
> ___
>
> 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/clarkcox3%40gmail.com
>
> This email sent to [EMAIL PROTECTED]
>



-- 
Clark S. Cox III
[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: BOOL array

2008-09-15 Thread Alex Reynolds
>
> Of course there's always std::vector< bool > ;-) usually at 1 bit per
> bit...
>
> --
> Scott Ribe
> [EMAIL PROTECTED]
> http://www.killerbytes.com/
> (303) 722-0567 voice


Thanks for the tip. So I ended up going the route of making my .m files into
.mm files, and using std::vector< vector > to store vectors of
vector's.

I found that iterator and const_iterator did not work on vector or
vector objects. I grabbed vector.size() in order to loop over the
vector.

Is there a difference in the underlying storage between vector and
vector? Is it really a vector of single bits or a vector of larger
data?

Are there any downsides to creating Cocoa-based applications in Objective
C++?

Thanks,
Alex
___

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: BOOL array

2008-09-11 Thread Clark Cox
On Thu, Sep 11, 2008 at 6:22 AM, dreamcat7 <[EMAIL PROTECTED]> wrote:
>
> On 11 Sep 2008, at 13:08, Jean-Daniel Dupas wrote:
>>
>> That's fine if you love to reinvent the wheel, but that exactly the
>> interface provided by CFMutableBitVector.
>>
>> CFBitVectorCreateMutable()
>> CFBitVectorSetBitAtIndex()
>> CFBitVectorGetBitAtIndex()
>>
>>
>> And it probably does it better as it will not waste 7 bits for each
>> option.
>>
>
> No, in a CFBitVector there is 4-bytes for each bit.

Not true. Internally, CFBitVector only uses 1 bit per bit. It's only
the parameter types that are 4-bytes (which makes sense as they are
passed in registers anyway).

-- 
Clark S. Cox III
[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: BOOL array

2008-09-11 Thread Michael Ash
On Wed, Sep 10, 2008 at 12:28 PM, Shawn Erickson <[EMAIL PROTECTED]> wrote:
> On Wed, Sep 10, 2008 at 9:18 AM, Joel Norvell <[EMAIL PROTECTED]> wrote:
>> OK.  I think I've got it.  One could use an increasing sequence of integers, 
>> letting evenness and oddness determine the boolean state at any index.  That 
>> would save a huge amount of "overhead" in this case!
>
> You only need to store the "index" of all the "ones" not need for
> even/odd business. You then walk the index set picking out the ones
> and marking down zeros for those indexes not in the set, etc.
>
> Of course the bit vector that someone suggested earlier is likely a
> better tool for this.

They are, in fact, essentially equivalent. The only difference in
terms of functionality is that CFBitVector can give you the index of
the top zero bit as well as the top one bit, whereas an NSIndexSet is
effectively always infinitely long. But if you don't care about
length, or you store it elsewhere, they provide identical
functionality with different APIs and implementations.

Mike
___

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: BOOL array

2008-09-11 Thread Peter N Lewis

At 14:22 +0100 11/9/08, dreamcat7 wrote:

On 11 Sep 2008, at 13:08, Jean-Daniel Dupas wrote:

And it probably does it better as it will not waste 7 bits for each option.


No, in a CFBitVector there is 4-bytes for each bit.

CFBit

A binary value of either 0 or 1.

typedef UInt32 CFBit;


The CFBit type is used only for parameters, it is not indicitive of 
how the bits are actually stored.


You can see the source code for a version of CFBitVector at



/* The bucket type must be unsigned, at least one byte in size, and a 
power of 2 in number of bits; bits are numbered from 0 from left to 
right (bit 0 is the most significant) */


__CF_BITS_PER_BYTE = 8
__CF_BITS_PER_BUCKET = (__CF_BITS_PER_BYTE * sizeof(__CFBitVectorBucket))

etc.

Of course there is no guarentee as to the storage, but I think it's 
safe to assume a guarantee of a little more than 1 bit per BOOL.


Enjoy,
   Peter.

--
  Keyboard Maestro 3 Now Available!
Now With Status Menu triggers!

Keyboard Maestro  Macros for your Mac
   
___

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: BOOL array

2008-09-11 Thread Chris Holloway
No, CFBit is just declared to be used in the interface of CFBitVector.
Look at 
http://http://src.gnu-darwin.org/DarwinSourceArchive/expanded/CF/CF-299/Collections.subproj/CFBitVector.c,
in particular the function __CFBitVectorBit. Each value has 1 bit of
overhead. Anything more is a needless waste.

2008/9/11 dreamcat7 <[EMAIL PROTECTED]>:
>
> On 11 Sep 2008, at 13:08, Jean-Daniel Dupas wrote:
>>
>> That's fine if you love to reinvent the wheel, but that exactly the
>> interface provided by CFMutableBitVector.
>>
>> CFBitVectorCreateMutable()
>> CFBitVectorSetBitAtIndex()
>> CFBitVectorGetBitAtIndex()
>>
>>
>> And it probably does it better as it will not waste 7 bits for each
>> option.
>>
>
> No, in a CFBitVector there is 4-bytes for each bit.
>
>
> CFBit
>
> A binary value of either 0 or 1.
>
> typedef UInt32 CFBit;
>
> Availability
>
>* Available in Mac OS X v10.0 and later.
>
> Declared In
> CFBitVector.h
>
> Incedentally if you do use NSMutableData to store your BOOLs (which ARE
> typedef signed char and hence 8-bits anyway), you are casting them to a
> char* which is very 'c-ish'. So you can then store 'C' bit array or any
> other byte-aligned c-type. So its not that bad !
>
>
> ___
>
> 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/c.holloway%40gmail.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: BOOL array

2008-09-11 Thread dreamcat7


On 11 Sep 2008, at 13:08, Jean-Daniel Dupas wrote:


That's fine if you love to reinvent the wheel, but that exactly the  
interface provided by CFMutableBitVector.


CFBitVectorCreateMutable()
CFBitVectorSetBitAtIndex()
CFBitVectorGetBitAtIndex()


And it probably does it better as it will not waste 7 bits for each  
option.




No, in a CFBitVector there is 4-bytes for each bit.


CFBit

A binary value of either 0 or 1.

typedef UInt32 CFBit;

Availability

* Available in Mac OS X v10.0 and later.

Declared In
CFBitVector.h

Incedentally if you do use NSMutableData to store your BOOLs (which  
ARE typedef signed char and hence 8-bits anyway), you are casting them  
to a char* which is very 'c-ish'. So you can then store 'C' bit array  
or any other byte-aligned c-type. So its not that bad !



___

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: BOOL array

2008-09-11 Thread Jean-Daniel Dupas


Le 11 sept. 08 à 13:32, dreamcat7 a écrit :



Yes the NSMutableData needs this category method then it work.


@interface  NSMutableData (charArray)
- (char*)char;
@end

@implementation NSMutableData (charArray)
- (char*)char
{
char * foo = self.mutableBytes;
return foo;
}
@end

+ (NSMutableData*)defaultOptions
{
NSMutableData* defaultOptions = [NSMutableData dataWithLength:20];
[defaultOptions char][03] = 0xFF;
[defaultOptions char][11] = 0xFF;
[defaultOptions char][19] = 0xFF;
// [defaultOptions char][] = YES;
	NSLog(@"%@:%s defaultOptions = %@", [self class], _cmd,  
defaultOptions);	

return [[defaultOptions retain] autorelease];
}


You can also declare your index numbers as an enum to make them easy  
to remember


enum MyOptions
{
MyOptionsFirstOption  = 00,
/* declare any more BOOL options */
MyOptionsNinteenthOption= 18,
MyOptionsLastOption  = 19,
MyOptionsLength  = 20,
};

which makes the [03] into [MyOption]

+ (NSMutableData*)defaultOptions
{
	NSMutableData* defaultOptions = [NSMutableData  
dataWithLength:MyOptionsLength];

[defaultOptions char][MyOptionsFirstOption] = YES;
[defaultOptions char][MyOptionsNinteenthOption] = YES;

// All other options are (signed char)0x00 = (BOOL)NO;

	NSLog(@"%@:%s defaultOptions = %@", [self class], _cmd,  
defaultOptions);	

return [[defaultOptions retain] autorelease];
}


And probably will also want to write kvc-compliant accessor methods
(for the ones which you would like exposed in your class' public  
interface)


- (BOOL)myFirstOption;
- (void)setMyFirstOption:(BOOL)theBool;




That's fine if you love to reinvent the wheel, but that exactly the  
interface provided by CFMutableBitVector.


CFBitVectorCreateMutable()
CFBitVectorSetBitAtIndex()
CFBitVectorGetBitAtIndex()


And it probably does it better as it will not waste 7 bits for each  
option.






___

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: BOOL array

2008-09-11 Thread dreamcat7


Yes the NSMutableData needs this category method then it work.


@interface  NSMutableData (charArray)
- (char*)char;
@end

@implementation NSMutableData (charArray)
- (char*)char
{
char * foo = self.mutableBytes;
return foo;
}
@end

+ (NSMutableData*)defaultOptions
{
NSMutableData* defaultOptions = [NSMutableData dataWithLength:20];
[defaultOptions char][03] = 0xFF;
[defaultOptions char][11] = 0xFF;
[defaultOptions char][19] = 0xFF;
// [defaultOptions char][] = YES;
	NSLog(@"%@:%s defaultOptions = %@", [self class], _cmd,  
defaultOptions);	

return [[defaultOptions retain] autorelease];
}


You can also declare your index numbers as an enum to make them easy  
to remember


enum MyOptions
{
MyOptionsFirstOption  = 00,
/* declare any more BOOL options */
MyOptionsNinteenthOption= 18,
MyOptionsLastOption  = 19,
MyOptionsLength  = 20,
};

which makes the [03] into [MyOption]

+ (NSMutableData*)defaultOptions
{
	NSMutableData* defaultOptions = [NSMutableData  
dataWithLength:MyOptionsLength];

[defaultOptions char][MyOptionsFirstOption] = YES;
[defaultOptions char][MyOptionsNinteenthOption] = YES;

// All other options are (signed char)0x00 = (BOOL)NO;

	NSLog(@"%@:%s defaultOptions = %@", [self class], _cmd,  
defaultOptions);	

return [[defaultOptions retain] autorelease];
}


And probably will also want to write kvc-compliant accessor methods
(for the ones which you would like exposed in your class' public  
interface)


- (BOOL)myFirstOption;
- (void)setMyFirstOption:(BOOL)theBool;



___

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: BOOL array

2008-09-11 Thread dreamcat7
" use NSMutableData objects with 1 byte for each 0 or 1 value. You  
can then get the BOOL values as
'data.bytes [index]', set them with 'data.mutableBytes [index] =  
someBool' and resize the array with
'data.length = someLength'. In terms of source code, that's about as  
minimalistic as it gets without

being pure C."



But mutableData is a void*. If we try to address it directly;

NSMutableData* defaultOptions = [NSMutableData dataWithLength:20];
defaultOptions.mutableBytes [03] = YES;

it gives the following compiler error

 warning: dereferencing 'void *' pointer
 error: invalid use of void expression



I believe this happens because ANSI C compiler cannot cast the LHS  
expression (to change the void* into a char*), and then it doesnt know  
how many bytes to increment to get to the [03] of the array because  
void type is sizeless.


From the apple examples, it shows we can make a temporary assignment  
and that will work;
http://developer.apple.com/documentation/Cocoa/Conceptual/BinaryData/Tasks/WorkingMutableData.html#/ 
/apple_ref/doc/uid/20002150-133973


NSMutableData* defaultOptions = [NSMutableData dataWithLength:20];
signed char * foo = defaultOptions.mutableBytes;
foo [03] = YES;

However needing the extra line for the assignment defeats the  
convenience.

Add a category method to NSMutableData which returns a char*  ?




___

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: BOOL array

2008-09-10 Thread Quincey Morris

... [earlier discussion] ...

NSIndexSet can use less than 1-bit per bit :)
(It compresses contiguous ranges)


In some cases, especially where 1s are relatively sparse, as with
selections. It can also take a whole lot more than 1 bit per bit,  
since a

range is a pair of 32-bit ints.
... [future discussion] ...


The difficulty with NSIndexSet as a solution is that it doesn't  
address the OP's question, which was how to control the performance  
and memory characteristics of an array of BOOL data items.


The original scenario was a NSMutableArray of NS(Mutable?)String  
objects each made up of a few hundred "0" or "1" characters. Trading  
this in for a NSMutableArray of NS(Mutable?)IndexSet objects *might*  
use less memory (or might not), but it might also be slower (because  
of checking for coalescing of index ranges).


The key point is that most of the implementation details of NSIndexSet  
are not known (and are not necessarily fixed for all time), so  
performance/memory characteristics are essentially unknown. What's the  
use of guessing?


Plus, the OP never stated what kinds of changes need to get made to  
the BOOL items. For all we know, the whole data structure is  
immutable. Or random BOOLs change thousands of times per second. The  
optimal solution depends on knowing which.


To pin down the performance/memory characteristics, you must pin down  
the implementation. That's why NSData in place of NSString seems to me  
to be an excellent solution. You know how much memory is going to be  
used (fractionally more than one byte per BOOL, on average, counting  
NSData's overheads) and you know the performance cost (at worst a  
method dispatch -- fractionally more than 1 function call, on average  
-- and a C pointer plus offset per BOOL access, if you code it as  
'data.bytes [index]'). These both seem very cheap, even if the target  
environment is (say) an iPhone.


Of course, this doesn't address the NSMutableArray part of the  
equation. We don't have enough information to know whether its  
performance/memory characteristics need to be taken into account.



___

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: BOOL array

2008-09-10 Thread Scott Ribe
> NSIndexSet can use less than 1-bit per bit :)
> (It compresses contiguous ranges)

In some cases, especially where 1s are relatively sparse, as with
selections. It can also take a whole lot more than 1 bit per bit, since a
range is a pair of 32-bit ints.

-- 
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: BOOL array

2008-09-10 Thread Clark Cox
NSIndexSet can use less than 1-bit per bit :)
(It compresses contiguous ranges)

On Wed, Sep 10, 2008 at 5:21 PM, Scott Ribe <[EMAIL PROTECTED]> wrote:
> Of course there's always std::vector< bool > ;-) usually at 1 bit per bit...



-- 
Clark S. Cox III
[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: BOOL array

2008-09-10 Thread Scott Ribe
Of course there's always std::vector< bool > ;-) usually at 1 bit per bit...

-- 
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: BOOL array

2008-09-10 Thread Joel Norvell
Yes, only storing "ones" would work well with NSMutableIndexSet's containsIndex 
method.  If you didn't get a "hit" you'd know that that position was a "zero."  
I was incorrectly thinking of NSMutableIndexSet as an array.

--- On Wed, 9/10/08, Shawn Erickson <[EMAIL PROTECTED]> wrote:

> On Wed, Sep 10, 2008 at 9:18 AM, Joel Norvell wrote:

> > OK.  I think I've got it.  One could use an
> > increasing sequence of integers, letting evenness and
> > oddness determine the boolean state at any index.  That
> > would save a huge amount of "overhead" in this case!
> 
> You only need to store the "index" of all the "ones" not need for
> even/odd business. You then walk the index set picking out the ones
> and marking down zeros for those indexes not in the set, etc.
> 
> Of course the bit vector that someone suggested earlier is likely a
> better tool for this.
> 




  
___

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: BOOL array

2008-09-10 Thread Shawn Erickson
On Wed, Sep 10, 2008 at 9:18 AM, Joel Norvell <[EMAIL PROTECTED]> wrote:
> OK.  I think I've got it.  One could use an increasing sequence of integers, 
> letting evenness and oddness determine the boolean state at any index.  That 
> would save a huge amount of "overhead" in this case!

You only need to store the "index" of all the "ones" not need for
even/odd business. You then walk the index set picking out the ones
and marking down zeros for those indexes not in the set, etc.

Of course the bit vector that someone suggested earlier is likely a
better tool for this.

(Sorry I just jumped into this thread so I may have missed a nuance of
exactly what he needs)

-Shawn
___

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: BOOL array

2008-09-10 Thread Igor Mozolevsky
2008/9/10 Joel Norvell <[EMAIL PROTECTED]>:
> OK.  I think I've got it.  One could use an increasing sequence of integers, 
> letting evenness and oddness determine the boolean state at any index.  That 
> would save a huge amount of "overhead" in this case!

Is the size of the boolean set always finite?

--
Igor
___

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: BOOL array

2008-09-10 Thread Joel Norvell
OK.  I think I've got it.  One could use an increasing sequence of integers, 
letting evenness and oddness determine the boolean state at any index.  That 
would save a huge amount of "overhead" in this case!

--- On Wed, 9/10/08, Todd Blanchard wrote:

> Well, if I read it right, he's using the NSString as a very expensive  
> bit vector - only storing 0's and 1's.
> 
> If instead of storing a '1' at position n he sticks n into the  
> NSMutableIndexSet, it amounts to the same thing.
> He can keep an array of NSMutableIndexSets instead of an
> array of NSStrings.
> 
> On Sep 9, 2008, at 11:51 PM, Joel Norvell wrote:
> 
> >
> > The values in an NSMutableIndexSet are always sorted, so the order  
> > in which they are added is not preserved. Wouldn't that defeat the  
> > purpose of the OP's data structure?
> >




  
___

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: BOOL array

2008-09-10 Thread Todd Blanchard
Well, if I read it right, he's using the NSString as a very expensive  
bit vector - only storing 0's and 1's.


If instead of storing a '1' at position n he sticks n into the  
NSMutableIndexSet, it amounts to the same thing.
He can keep an array of NSMutableIndexSets instead of an array of  
NSStrings.


On Sep 9, 2008, at 11:51 PM, Joel Norvell wrote:

I'm resending this to correct an egregious attribution error in my  
previous post.  My comment remains the same.



On Sep 9, 2008, at 03:24, Alex Reynolds wrote:



I am currently putting 320 to 480 character long NSString *
instances into an NSMutableArray. The characters are 0 or 1.

I guess I could use an int array, but I'm looking to speed up my app
and reduce storage. Is it possible to create a BOOL array that can
be put into an NSMutableArray?



On Sep 10, 2008, at 02:32, Todd Blanchard wrote:



You might consider using a NSMutableIndexSet since your problem
basically boils down to storing membership in a set for each of a
ranch of numbers.  NSIndexSet is what things like NSTable use to  
track

selected rows.  I would think it would be hard to beat that without
going to a raw C bitmap implementation.  It will be MUCH better than
what you have now.


The values in an NSMutableIndexSet are always sorted, so the order  
in which they are added is not preserved.  Wouldn't that defeat the  
purpose of the OP's data structure?






___

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/tblanchard%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]


Re: BOOL array

2008-09-09 Thread Joel Norvell
I'm resending this to correct an egregious attribution error in my previous 
post.  My comment remains the same.

> > On Sep 9, 2008, at 03:24, Alex Reynolds wrote:

> > I am currently putting 320 to 480 character long NSString *  
> > instances into an NSMutableArray. The characters are 0 or 1.
> >
> > I guess I could use an int array, but I'm looking to speed up my app  
> > and reduce storage. Is it possible to create a BOOL array that can  
> > be put into an NSMutableArray?

> On Sep 10, 2008, at 02:32, Todd Blanchard wrote:

> You might consider using a NSMutableIndexSet since your problem  
> basically boils down to storing membership in a set for each of a  
> ranch of numbers.  NSIndexSet is what things like NSTable use to track  
> selected rows.  I would think it would be hard to beat that without  
> going to a raw C bitmap implementation.  It will be MUCH better than  
> what you have now.

The values in an NSMutableIndexSet are always sorted, so the order in which 
they are added is not preserved.  Wouldn't that defeat the purpose of the OP's 
data structure?




  
___

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: BOOL array

2008-09-09 Thread Joel Norvell
> On Sep 9, 2008, at 18:43, Quincey Morris wrote:

> > On Sep 9, 2008, at 03:24, Alex Reynolds wrote:

> > I am currently putting 320 to 480 character long NSString *  
> > instances into an NSMutableArray. The characters are 0 or 1.
> >
> > I guess I could use an int array, but I'm looking to speed up my app  
> > and reduce storage. Is it possible to create a BOOL array that can  
> > be put into an NSMutableArray?

> Or use NSMutableData objects with 1 byte for each 0 or 1 value. You  
> can then get the BOOL values as 'data.bytes [index]', set them with  
> 'data.mutableBytes [index] = someBool' and resize the array with  
> 'data.length = someLength'. In terms of source code, that's about as  
> minimalistic as it gets without being pure C.

The values in an NSMutableIndexSet are always sorted, so the order in which 
they are added is not preserved.  Wouldn't that defeat the purpose of the OP's 
data structure?




  
___

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: BOOL array

2008-09-09 Thread Todd Blanchard
You might consider using a NSMutableIndexSet since your problem  
basically boils down to storing membership in a set for each of a  
ranch of numbers.  NSIndexSet is what things like NSTable use to track  
selected rows.  I would think it would be hard to beat that without  
going to a raw C bitmap implementation.  It will be MUCH better than  
what you have now.


-Todd Blanchard

On Sep 9, 2008, at 3:24 AM, Alex Reynolds wrote:

I am currently putting 320 to 480 character long NSString *  
instances into an NSMutableArray. The characters are 0 or 1.


I guess I could use an int array, but I'm looking to speed up my app  
and reduce storage. Is it possible to create a BOOL array that can  
be put into an NSMutableArray?


Thanks,
Alex
___

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/tblanchard%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]


Re: BOOL array

2008-09-09 Thread Andy Lee

On Sep 9, 2008, at 12:43 PM, Quincey Morris wrote:

On Sep 9, 2008, at 03:24, Alex Reynolds wrote:

I am currently putting 320 to 480 character long NSString *  
instances into an NSMutableArray. The characters are 0 or 1.


I guess I could use an int array, but I'm looking to speed up my  
app and reduce storage. Is it possible to create a BOOL array that  
can be put into an NSMutableArray?


Or use NSMutableData objects with 1 byte for each 0 or 1 value. You  
can then get the BOOL values as 'data.bytes [index]', set them with  
'data.mutableBytes [index] = someBool' and resize the array with  
'data.length = someLength'. In terms of source code, that's about as  
minimalistic as it gets without being pure C.


Very nice.  This is simple, it performs well, and depending on how  
you're storing the data, might possibly cut down the storage space of  
your array significantly (for example if you're using a plist).


My only question would be how many of these arrays you have and how  
often you're stuffing booleans into them, and whether you're sure  
operations on this array are actually taking a noticeable amount of  
time.


--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: BOOL array

2008-09-09 Thread Andrew Merenbach

On Sep 9, 2008, at 3:24 AM, Alex Reynolds wrote:

I am currently putting 320 to 480 character long NSString *  
instances into an NSMutableArray. The characters are 0 or 1.


I guess I could use an int array, but I'm looking to speed up my app  
and reduce storage. Is it possible to create a BOOL array that can  
be put into an NSMutableArray?


Thanks,
Alex


Hi!  You might save some memory by using [NSNumber numberWithBool:YES]  
and [NSNumber numberWithBool:NO] as your NSMutableArray contents --  
that way you're not wasting strings.


Cheers,
Andrew


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: BOOL array

2008-09-09 Thread Quincey Morris

On Sep 9, 2008, at 03:24, Alex Reynolds wrote:

I am currently putting 320 to 480 character long NSString *  
instances into an NSMutableArray. The characters are 0 or 1.


I guess I could use an int array, but I'm looking to speed up my app  
and reduce storage. Is it possible to create a BOOL array that can  
be put into an NSMutableArray?


Or use NSMutableData objects with 1 byte for each 0 or 1 value. You  
can then get the BOOL values as 'data.bytes [index]', set them with  
'data.mutableBytes [index] = someBool' and resize the array with  
'data.length = someLength'. In terms of source code, that's about as  
minimalistic as it gets without being pure C.




___

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: BOOL array

2008-09-09 Thread Jean-Daniel Dupas

Le 9 sept. 08 à 12:24, Alex Reynolds a écrit :

I am currently putting 320 to 480 character long NSString *  
instances into an NSMutableArray. The characters are 0 or 1.


I guess I could use an int array, but I'm looking to speed up my app  
and reduce storage. Is it possible to create a BOOL array that can  
be put into an NSMutableArray?




I you don't need to much control over you data, you may use a  
CFBitVector (and mutable counterpart).
As it is a CFTypeRef, it is free-bridged with NSObject and can be  
stored in an NSArray.



___

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: BOOL array

2008-09-09 Thread Jason Coco


On Sep 9, 2008, at 06:24 , Alex Reynolds wrote:

I am currently putting 320 to 480 character long NSString *  
instances into an NSMutableArray. The characters are 0 or 1.


I guess I could use an int array, but I'm looking to speed up my app  
and reduce storage. Is it possible to create a BOOL array that can  
be put into an NSMutableArray?


You can use a BOOL array or an int array... or an array of uint8_t.  
BOOL is just a signed char anyway. Just wrap the array in an NSValue  
object when you put it into the NSMutableArray:


BOOL boolArrayOne[320];

/* ... */

NSValue *boolArrayOneAsValue = [NSValue valueWithPointer:&boolArrayOne];

Jason

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]

BOOL array

2008-09-09 Thread Alex Reynolds
I am currently putting 320 to 480 character long NSString * instances  
into an NSMutableArray. The characters are 0 or 1.


I guess I could use an int array, but I'm looking to speed up my app  
and reduce storage. Is it possible to create a BOOL array that can be  
put into an NSMutableArray?


Thanks,
Alex
___

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]