[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Memory Size of 1 Mio Point Polyline table?
- From: bil til <biltil52@...>
- Date: Tue, 25 Oct 2022 07:46:50 +0200
Are you sure?
To my understanding from the "#if..." precompiler constructions in
luaconf.h, it is sufficient to set:
#define LUA_32BITS 1
Then further down you have the code (last line with LUA_FLOAT_FLOAT is
the crucial line):
#if LUA_32BITS /* { */
/*
** 32-bit integers and 'float'
*/
#if LUAI_IS32INT /* use 'int' if big enough */
#define LUA_INT_TYPE LUA_INT_INT
#else /* otherwise use 'long' */
#define LUA_INT_TYPE LUA_INT_LONG
#endif
#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT
The define LUAI_IS32INT is set "automatically correct":
/*
@@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits.
*/
#define LUAI_IS32INT ((UINT_MAX >> 30) >= 3)
(this might be a bit a "dangerous define" in case of 64bit compilers
that keep int's as 32bit and require "long int" for the "standard 64
bit ints". ... to facilitate the transfer of 32bit windows to 64bit
windows, MS Visual Studio C++ does this trick, if you select Win64...
but as I see it in luaconf, this define LUAI_IS32INT is ONLY used if
LUA_32BITS is active... and in this case typically you should have
32bit compiler with 32 bit floats and ints, and then all fine...).
So if you set LUA_32BITS in case of a 32bit compiler, then all fine
for usage of 32bit pointers, 32bit floats and 32bit ints... . And in
this case then sizeof (TValue) would have been 4+4= 8 in Lua 5.1
times.
And currently in Lua 5.4 it is 4+1= 5, as I see it, see TValue
definition in lobject.h:
#define TValuefields Value value_; lu_byte tt_
typedef struct TValue {
TValuefields;
} TValue;
(The defines for Value are given a bit above in this file:
typedef union Value {
struct GCObject *gc; /* collectable objects */
void *p; /* light userdata */
lua_CFunction f; /* light C functions */
lua_Integer i; /* integer numbers */
lua_Number n; /* float numbers */
} Value;
... (in llimits.h:)...
typedef unsigned char lu_byte;
... (in lua.h:)...
/* type of numbers in Lua */
typedef LUA_NUMBER lua_Number;
/* type for integer functions */
typedef LUA_INTEGER lua_Integer;
.. (in luaconf.h:)...
#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */
#define LUA_NUMBER float
...
#define LUA_INTEGER int
... so if you do all these replacements, then you end with LUA_32BITS:
#define TValuefields Value value_; unsigned char tt_
typedef union Value {
struct GCObject *gc; /* collectable objects */
void *p; /* light userdata */
lua_CFunction f; /* light C functions */
int i; /* integer numbers */
float n; /* float numbers */
} Value;
... and if you are using a 32bit compiler, then Value thus will be
32bits, so sizeof(TValue)=4+1=5.