SQLite Forum

ORDER BY not working for a specific DB/table
Note that if you use any `__float128` types in `sqlite3_malloc`'d space, you will need the following to be defined for MinGW GCC on Windows.  This is because GCC on Windows uses the Windows subsystem memory allocator (which returns all allocations 16-byte aligned), but the current code does not recognize this so it makes all allocations 8 bytes bigger so that the first 8 bytes can contain the allocation size and offsets the returned pointer so that it is only 8-byte aligned.

So if you use allocated memory to point to a structure which contains an element requiring 16-byte alignment, the compiler's alignment assumptions will fail and you will coredump with an alignment fault.

The `SQLITE_USE_MALLOC` tells the compiler that the Operating System heap manager is managing the allocation size (so the library does not have to do it) and the `SQLITE_USE_MSIZE` tells the code to use the Windows subsystem API `(_msize)` to get the allocation size rather than the "standard" C library API (which does not work on Windows).

This only applies to `__float128` on heap allocations made directly or indirectly using sqlite3_malloc.  Allocations on the stack or in constant data segments or on directly malloc'd heap will always be properly aligned.

#define SQLITE_USE_MALLOC_H 1                                   // Platform has malloc.h
#define SQLITE_USE_MSIZE 1                                      // Platform malloc_usable_size is _msize