On 26 Mar 2014, at 00:14, Rick Mann <rm...@latencyzero.com> wrote:

> When dealing with structures on disk, I've created packed structs that 
> exactly match the on-disk layout, then applied byte swapping before writing 
> or after reading as appropriate. Then I just write or read the struct as a 
> buffer. This gets a bit trickier for variable-size data, but works for the 
> fixed-size portions of things.

I was thinking this myself, the problem being there are variable number of 
entries and most of them have offsets to array’s of structs within the file and 
other parts of of file address them with indices into the array.  e.g.
Offset to Array of Arrays       Point to the List below.                
Count of Arrays

ArrayList:
Offset to Start of Array1                       32 Bits
Count of Array1 Entries                 32 Bits
Offset to Start of Array2                       32 Bits
Count of Array2 Entries                 32 Bits


Array1:
{
  Item1:
  {
  Value1                                                16Bits
  Value2                                                16Bits
  Value3                                                C-String
  Value4                                                32 Bits
  Value5                                                32 Bits
  }
  Item2:
  {
  Value1                                                16Bits
  Value2                                                16Bits
  Value3                                                C-String
  Value4                                                32 Bits
  Value5                                                32 Bits
  }
 ItemN:
  {
  Value1                                                16Bits
  Value2                                                16Bits
  Value3                                                C-String
  Value4                                                32 Bits
  Value5                                                32 Bits
  }
}

Array2:
{
  Item1:
  {
  Value1                                                16Bits
  Value2                                                16Bits
  Value3                                                C-String
  Value4                                                32 Bits
  Value5                                                32 Bits
  }
  Item2:
  {
  Value1                                                16Bits
  Value2                                                16Bits
  Value3                                                C-String
  Value4                                                32 Bits
  Value5                                                32 Bits
  }
 ItemN:
  {
  Value1                                                16Bits
  Value2                                                16Bits
  Value3                                                C-String
  Value4                                                32 Bits
  Value5                                                32 Bits
  }
}

Some other part of the file:

Offset to Array1
Count of Indcies
Index1  3
Index2  1
Indexn     n


The other problem is that although most of the fields are variables, there are 
some stings involved. These take a number of forms, from standard C-Strings as 
well as a Pointer/Count structure. I was thinking of converting these to 
NSString’s and where there is a file array of items, make Item Objects for them 
and hold in an NSArray property of the parent object.

My initial thoughts was to turn all integer values regardless of size into 
NSInteger’s on read and back into their file size on write. But as someone else 
pointed out this results in a lot wastage, (about 70% I should think).

> Anyway, I would use something like that as a temporary mechanism to import 
> the data into the app's new data structures, and generally I use 32-bit sizes 
> for most storage of things (rarely do you need more, but if you have a lot 
> and you know they're small, use a smaller int, but don't be too aggressive 
> with that, especially if there's potential future need for more range).

As far as I am aware there are no 64 bit values I’d say that there that about 
60% are 16 bit, 30% 32 bit and 10% 8 bit.

I suppose if I made everything 32 bits, it would be a lot better than 64 bits 
in terms of space wasted. 

Hmmmmmmm, I’ll decide soon!

Thanks for your comments and suggests.
Dave











_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to