Set packing 
Author Message
 Set packing

In the gpc demos, the keyword "packed" forces records to the minimum byte
boundary.  Is there an analogous method for sets?  I'm looking for something
like this:

    column = (c0, c1, c2, c3, c4, c5);
    columnset = SET of column; // Want this to be 1 byte.

    bit = (b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15);
    bitset    = SET OF bit;  // Want this to be 2 bytes.

Is there a compiler directive or keyword that will accomplish this?

Jim.



Sat, 24 Sep 2005 22:02:39 GMT  
 Set packing

Quote:

> In the gpc demos, the keyword "packed" forces records to the minimum byte
> boundary.  Is there an analogous method for sets?  I'm looking for something
> like this:

>     column = (c0, c1, c2, c3, c4, c5);
>     columnset = SET of column; // Want this to be 1 byte.

>     bit = (b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15);
>     bitset    = SET OF bit;  // Want this to be 2 bytes.

> Is there a compiler directive or keyword that will accomplish this?

Unfortunately not (currently).

Frank

--

GnuPG and PGP keys:         http://fjf.gnu.de/plan (7977168E)
Pascal code, BP CRT bugfix: http://fjf.gnu.de/programs.html
Free GNU Pascal Compiler:   http://www.gnu-pascal.de/



Thu, 06 Oct 2005 19:20:41 GMT  
 Set packing

Quote:


> > In the gpc demos, the keyword "packed" forces records to the
> > minimum byte boundary.  Is there an analogous method for sets?
> > I'm looking for something like this:

> >     column = (c0, c1, c2, c3, c4, c5);
> >     columnset = SET of column; // Want this to be 1 byte.

> >     bit = (b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15);
> >     bitset    = SET OF bit;  // Want this to be 2 bytes.

> > Is there a compiler directive or keyword that will accomplish
> > this?

> Unfortunately not (currently).

Er - how do you pack sets?  They already contain only one bit per
item, and I fail to see any way to reduce that.

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!



Thu, 06 Oct 2005 22:35:36 GMT  
 Set packing

Quote:



>> > In the gpc demos, the keyword "packed" forces records to the
>> > minimum byte boundary.  Is there an analogous method for sets?
>> > I'm looking for something like this:

>> >     column = (c0, c1, c2, c3, c4, c5);
>> >     columnset = SET of column; // Want this to be 1 byte.

>> >     bit = (b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15);
>> >     bitset    = SET OF bit;  // Want this to be 2 bytes.

>> > Is there a compiler directive or keyword that will accomplish
>> > this?

>> Unfortunately not (currently).

> Er - how do you pack sets?  They already contain only one bit per
> item, and I fail to see any way to reduce that.

Usually they are, but they don't have to be. And there may be padding.

IOW there is no mandatory correlation between sizeof(settype) and number of elements.

FPC for example has this:

1..8 elements : 1 byte
9..32         : 4 bytes
33.256        : 32 bytes



Thu, 06 Oct 2005 22:42:27 GMT  
 Set packing

Quote:




> >> > In the gpc demos, the keyword "packed" forces records to the
> >> > minimum byte boundary.  Is there an analogous method for sets?
> >> > I'm looking for something like this:

> >> >     column = (c0, c1, c2, c3, c4, c5);
> >> >     columnset = SET of column; // Want this to be 1 byte.

> >> >     bit = (b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15);
> >> >     bitset    = SET OF bit;  // Want this to be 2 bytes.

> >> > Is there a compiler directive or keyword that will accomplish
> >> > this?

> >> Unfortunately not (currently).

> > Er - how do you pack sets?  They already contain only one bit per
> > item, and I fail to see any way to reduce that.

> Usually they are, but they don't have to be. And there may be padding.

> IOW there is no mandatory correlation between sizeof(settype) and
> number of elements.

> FPC for example has this:

> 1..8 elements : 1 byte
> 9..32         : 4 bytes
> 33.256        : 32 bytes

IMO that's not packing, that's assigning storage to suit the data
type.  The type is not SET, it is SET OF ...

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!



Fri, 07 Oct 2005 09:36:49 GMT  
 Set packing

Quote:





> > >> > In the gpc demos, the keyword "packed" forces records to the
> > >> > minimum byte boundary.  Is there an analogous method for sets?
> > >> > I'm looking for something like this:

> > >> >     column = (c0, c1, c2, c3, c4, c5);
> > >> >     columnset = SET of column; // Want this to be 1 byte.

> > >> >     bit = (b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15);
> > >> >     bitset    = SET OF bit;  // Want this to be 2 bytes.

> > >> > Is there a compiler directive or keyword that will accomplish
> > >> > this?

> > >> Unfortunately not (currently).

> > > Er - how do you pack sets?  They already contain only one bit per
> > > item, and I fail to see any way to reduce that.

> > Usually they are, but they don't have to be. And there may be padding.

> > IOW there is no mandatory correlation between sizeof(settype) and
> > number of elements.

> > FPC for example has this:

> > 1..8 elements : 1 byte
> > 9..32         : 4 bytes
> > 33.256        : 32 bytes

> IMO that's not packing, that's assigning storage to suit the data
> type.  The type is not SET, it is SET OF ...

Its packing to byte boundaries. What you are thinking is packing to
bit boundaries. Is that the ultimate packing ? Whoops, no it isn't !
There is arithmetic packing, that gets you down below the bit.

--
It amazes me that programmers feel the need to program in
the same language as others. The advantages of different
hair growing products are better established than the
advantages of any particular choice of language.



Fri, 07 Oct 2005 12:50:03 GMT  
 Set packing

Quote:





>> >> > In the gpc demos, the keyword "packed" forces records to the
>> >> > minimum byte boundary.  Is there an analogous method for sets?
>> >> > I'm looking for something like this:

>> >> >     column = (c0, c1, c2, c3, c4, c5);
>> >> >     columnset = SET of column; // Want this to be 1 byte.

>> >> >     bit = (b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15);
>> >> >     bitset    = SET OF bit;  // Want this to be 2 bytes.

>> >> > Is there a compiler directive or keyword that will accomplish
>> >> > this?

>> >> Unfortunately not (currently).

>> > Er - how do you pack sets?  They already contain only one bit per
>> > item, and I fail to see any way to reduce that.

>> Usually they are, but they don't have to be. And there may be padding.

>> IOW there is no mandatory correlation between sizeof(settype) and
>> number of elements.

>> FPC for example has this:

>> 1..8 elements : 1 byte
>> 9..32         : 4 bytes
>> 33.256        : 32 bytes

> IMO that's not packing, that's assigning storage to suit the data
> type.  The type is not SET, it is SET OF ...

- It's what the OP asked about.
- The elements are bitwise packed. This is for simple types as far as it
  goes. (sparse sets etc excluded as more complicated mechanism).
- Packing to bitlevel borders (4 elements, 4 bits) is something for the structure
  on top of this set structure to decide (iow the packing of the record this
  struct is in)
- I don't get your last remark (SET, SET OF ?)


Fri, 07 Oct 2005 20:50:18 GMT  
 Set packing

Quote:

... snip ...

> - I don't get your last remark (SET, SET OF ?)

  TYPE
     foo    = SET OF char;  /* is a type */
     bar    = SET OF 1..12; /* is also a type */
     foobar = SET;          /* is a syntax error */

foo and bar can have widely different storage requirements,
although in many implementations their storage space will be the
same.  Similarly:

     range1 = -127 .. 128;
     range2 = 0 .. 10000;

*can* have different storage requirements, but will often be the
same.  The sort of thing one packs is an array,  where

    a1 = PACKED ARRAY[1..10] OF range1;

*MAY* economize on storage.  It doesn't have to.  According to
ISO7185 the proper way to install things in that array, and to get
them out, is with the PACK/UNPACK standard procedures.  "a1[2] =
a1[3] + 3;" should be a syntax error.  Widely ignored if the
system doesn't do any actual packing.  PACKED RECORD access is not
so restricted.  IIRC.

With the PACKED ARRAY the programmer is saying 'I want to
economize on storage, and I am willing to pay the penalty of
access via PACK/UNPACK'.

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!



Sat, 08 Oct 2005 01:44:08 GMT  
 Set packing
I'm trying to recompile some old metaware pascal under GPC or FPC.  It's
sets are 1 byte, 2 bytes, and 4, 8, ... for
sets with 8, 16, 32, 64, ... elements.   I saw that GPC and FPC can pack
down record structures and enums, and
was wondering if it could also force 8 and 16 element sets into 1 and 2
bytes respectively.  Also on your note of FPC,
so far, I've found sets are always at least 4 bytes.

Jim.



Quote:



> >> > In the gpc demos, the keyword "packed" forces records to the
> >> > minimum byte boundary.  Is there an analogous method for sets?
> >> > I'm looking for something like this:

> >> >     column = (c0, c1, c2, c3, c4, c5);
> >> >     columnset = SET of column; // Want this to be 1 byte.

> >> >     bit = (b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15);
> >> >     bitset    = SET OF bit;  // Want this to be 2 bytes.

> >> > Is there a compiler directive or keyword that will accomplish
> >> > this?

> >> Unfortunately not (currently).

> > Er - how do you pack sets?  They already contain only one bit per
> > item, and I fail to see any way to reduce that.

> Usually they are, but they don't have to be. And there may be padding.

> IOW there is no mandatory correlation between sizeof(settype) and number
of elements.

> FPC for example has this:

> 1..8 elements : 1 byte
> 9..32       : 4 bytes
> 33.256       : 32 bytes



Sat, 08 Oct 2005 03:01:08 GMT  
 Set packing

Quote:

>> Usually they are, but they don't have to be. And there may be padding.

>> IOW there is no mandatory correlation between sizeof(settype) and number
> of elements.

>> FPC for example has this:

>> 1..8 elements : 1 byte
>> 9..32       : 4 bytes
>> 33.256       : 32 bytes
> I'm trying to recompile some old metaware pascal under GPC or FPC.  It's
> sets are 1 byte, 2 bytes, and 4, 8, ... for
> sets with 8, 16, 32, 64, ... elements.   I saw that GPC and FPC can pack
> down record structures and enums, and
> was wondering if it could also force 8 and 16 element sets into 1 and 2
> bytes respectively.  Also on your note of FPC,
> so far, I've found sets are always at least 4 bytes.

Hmm yes, only  4 or 32 byte. There was some support for 1 byte, but it never
got fully enabled.  And 256 elements maximally.

There is no other way. This is a known implementation problem. (mainly to
Delphi compability)



Sat, 08 Oct 2005 05:47:29 GMT  
 Set packing

Quote:


> ... snip ...

>> - I don't get your last remark (SET, SET OF ?)

>   TYPE
>      foo    = SET OF char;  /* is a type */
>      bar    = SET OF 1..12; /* is also a type */
>      foobar = SET;          /* is a syntax error */

Yes of course (!?!?)

Quote:
> foo and bar can have widely different storage requirements,
> although in many implementations their storage space will be the
> same.  Similarly:
>      range1 = -127 .. 128;
>      range2 = 0 .. 10000;

> *can* have different storage requirements, but will often be the
> same.  The sort of thing one packs is an array,  where

Yes, but these are not sets, but sub-ranges. So not relevant. Under FPC this
can be steered by the $PACKENUM directive, but default is to use the
"integer", or in v1.1 integer, but (probably) use 64-bits int if the range
is larger than 2^32.

Quote:
>     a1 = PACKED ARRAY[1..10] OF range1;
> *MAY* economize on storage.  It doesn't have to.

Borland-like compilers typically don't, and only do byte level packing. The
packed directive usually only skips alignment for records -fields, and is a
no-op for arrays (since arrays aren't usually packed)


Sat, 08 Oct 2005 05:56:06 GMT  
 Set packing

[snip]

Quote:
> ... Similarly:

>      range1 = -127 .. 128;
>      range2 = 0 .. 10000;

> *can* have different storage requirements, but will often be the
> same.  The sort of thing one packs is an array,  where

>     a1 = PACKED ARRAY[1..10] OF range1;

> *MAY* economize on storage.  It doesn't have to.  According to
> ISO7185 the proper way to install things in that array, and to get
> them out, is with the PACK/UNPACK standard procedures.  "a1[2] =
> a1[3] + 3;" should be a syntax error.  Widely ignored if the
> system doesn't do any actual packing.  PACKED RECORD access is not
> so restricted.  IIRC.

I'm pretty certain that you're mistaken about "a1[2] = a1[3] + 3;"
being a syntax error.  Doesn't make any difference as to what sort of
packed stuctured type you are working with, that sort of code construct
is perfectly legal.  The only restriction on using components of a
packed structured type is the prohibition of using one as the actual
parameter for a formal VAR parameter.

While PACKED does have significance in type compatibility, its
significance is on the structured type to which it has been been
applied and not on the element, field, etc. component of the structured
type.  The component only has a PACKED type designation if the
component itself has a PACKED type denoter.  Since only structued types
can be desinated PACKED, there is no packed involved in the type
compatibility rules in play in the example.  The types involved are
just integer and integer subrange which by definition is fully type
compatible.

The PACK/UNPACK standard procedures are transfer procedures provided
solely for programmer convenience and implementation machine tuned
performace potentialities.  The fuctionality of PACK/UNPACK can be
duplicated by element by element assignment statements to tranfer
elements to and from packed and non-packed arrays in a manner similar
to what is required for transfering to and from packed and unpacked
records.

Gale Paeper



Sat, 08 Oct 2005 18:32:57 GMT  
 Set packing

Quote:



> [snip]
> > ... Similarly:

> >      range1 = -127 .. 128;
> >      range2 = 0 .. 10000;

> > *can* have different storage requirements, but will often be the
> > same.  The sort of thing one packs is an array,  where

> >     a1 = PACKED ARRAY[1..10] OF range1;

> > *MAY* economize on storage.  It doesn't have to.  According to
> > ISO7185 the proper way to install things in that array, and to get
> > them out, is with the PACK/UNPACK standard procedures.  "a1[2] =
> > a1[3] + 3;" should be a syntax error.  Widely ignored if the
> > system doesn't do any actual packing.  PACKED RECORD access is not
> > so restricted.  IIRC.

> I'm pretty certain that you're mistaken about "a1[2] = a1[3] + 3;"
> being a syntax error.  Doesn't make any difference as to what sort of
> packed stuctured type you are working with, that sort of code construct
> is perfectly legal.  The only restriction on using components of a
> packed structured type is the prohibition of using one as the actual
> parameter for a formal VAR parameter.

> While PACKED does have significance in type compatibility, its
> significance is on the structured type to which it has been been
> applied and not on the element, field, etc. component of the structured
> type.  The component only has a PACKED type designation if the
> component itself has a PACKED type denoter.  Since only structued types
> can be desinated PACKED, there is no packed involved in the type
> compatibility rules in play in the example.  The types involved are
> just integer and integer subrange which by definition is fully type
> compatible.

> The PACK/UNPACK standard procedures are transfer procedures provided
> solely for programmer convenience and implementation machine tuned
> performace potentialities.  The fuctionality of PACK/UNPACK can be
> duplicated by element by element assignment statements to tranfer
> elements to and from packed and non-packed arrays in a manner similar
> to what is required for transfering to and from packed and unpacked
> records.

> Gale Paeper


Yes to that, pack/unpack are simply the way to get and put the entire contents
of an array at once, efficiently. The marking of a packed array does not change
the semantics of the array at all. The user is supposed to understand they are
trading off speed of access for storage, nothing more.

--
It amazes me that programmers feel the need to program in
the same language as others. The advantages of different
hair growing products are better established than the
advantages of any particular choice of language.



Sun, 09 Oct 2005 00:15:19 GMT  
 Set packing

Quote:

> [snip]

> I'm pretty certain that you're mistaken about "a1[2] = a1[3] + 3;"
> being a syntax error.  Doesn't make any difference as to what sort of
> packed stuctured type you are working with, that sort of code construct
> is perfectly legal.  The only restriction on using components of a
> packed structured type is the prohibition of using one as the actual
> parameter for a formal VAR parameter.

I think you are right, and I have made this error before.

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!



Sun, 09 Oct 2005 01:54:28 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. Table pack error (was: packing a database [delphi])

2. How to pack the table in delphi 5

3. pack Table

4. How do you pack a paradox tables?

5. Apollo & Packing

6. Packing Of Paradox Database

7. packing a table

8. How to pack a DBase table in Delphi 3

9. How to Pack Paradox tables in run-time

10. DBase Packing?

11. More on packing with BDE

12. How to pack/reindex DBase3 files?

 

 
Powered by phpBB® Forum Software