Mathieu Bouchard wrote:
On Sat, 16 Dec 2006, Martin Peach wrote:

Yes, and it's also easier to limit strings to word (16-bit) lengths, while 8-bit is too short. So a t_string would look like:
typedef struct _string /* pointer to a string */
{
 unsigned short s_length; /* length of string in bytes */
 unsigned char *s_data; /* pointer to 1st byte of string */
} t_string;

If you're not compiling in 16-bit mode, then there will be 2 or 6 bytes between the first and second field, so that the second field can be aligned to a word boundary, supposing that the struct as a whole is itself aligned to a word boundary. (By word, I strictly mean something that is the same size as a pointer.)

What I mean is that it's useless to not use the whole a length field that is not the same size as the pointer field, if you have only those two fields. If you have more than two fields, then you can put several short fields in the space of a word (2 or 4).
I suppose we could do like Apple or Microsoft and have something like:

typedef struct _string /* pointer to a string */
{
   unsigned short s_length; /* length of string in bytes */
   unsigned short s_reserved; /* filler */
   unsigned char *s_data; /* pointer to 1st byte of string */
} t_string;

but in the long term it would be best to just use long lengths for when we all have teraflop laptops:

typedef struct _string /* pointer to a string */
{
   unsigned long s_length; /* length of string in bytes */
   unsigned char *s_data; /* pointer to 1st byte of string */
} t_string;

...but restrict the maximum string length using a #define MAX_STRING_LENGTH so that pd doesn't bite off more than it can chew...

Martin

_______________________________________________
PD-dev mailing list
PD-dev@iem.at
http://lists.puredata.info/listinfo/pd-dev

Reply via email to