lua-users home
lua-l archive

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


> #define ARRAY_FLEXIBLE_MEMBER            1
> 
> Lua 5.4.2 Windows (64 bits)
> type sizes (bytes):
> Struct                             Size
> [...]
> Udata                                48
> CClosure                          48
> [...]
> 
> #define ARRAY_FLEXIBLE_MEMBER            0
> 
> Lua 5.4.2 Windows (64 bits)
> type sizes (bytes):
> Struct                             Size
> [...]
> Udata                               32
> CClosure                         32
> [...]

I believe you are printing the result of 'sizeof'. What Gé just
explained is that we don't use 'sizeof' for these structures.
If you print the result of 'offsetof' for the last field of
each structure (which is what Lua uses), you will see that the
actual size of those arrays (that is, the value of ARRAY_FLEXIBLE_MEMBER)
is irrelevant.

As a quick experiment, change the size of these arrays to something
absurdly large, such as this:

     size_t lnglen;  /* length for long strings */
     struct TString *hnext;  /* linked list for hash table */
   } u;
-  char contents[1];
+  char contents[1000000];
 } TString;

The resulting code uses exactly as much memory as the original.

-- Roberto