Hello all,

                SQLite currently has a SQLITE_USE_ALLOCA define in which
it will attempt to use alloca instead of malloc when the usage fits.
One of the common dangers with alloca is that if there is not enough
stack space, bad things happen and it's usually very difficult to debug.
Microsoft Visual Studio offers the function _malloca which will allocate
stack space if the amount is within a threshold OR it will malloc if the
amount is beyond the threshold.  I find myself frequently adding  the
following code to each new release of SQLite to support _malloca and was
curious if others would find it useful:

 

Just before "#ifdef SQLITE_USE_ALLOCA"..

#ifdef SQLITE_USE_MALLOCA

# define sqlite3StackAllocRaw(D,N)   _malloca(N)

# define sqlite3StackAllocZero(D,N)  memset(_malloca(N), 0, N)

# define sqlite3StackFree(D,P)       _freea(P);

#else

 

The two caveats I see that would probably prevent this from being
standard would be that _malloca may not exist on all platforms and that
_malloca can potentially bypass the memory management routines put in
place for SQLite (since _malloca will internally call malloc if there is
not enough stackspace).  Still, it serves as a nice safety net to those
who like using alloca but fear the dangers of it :)

 

-Shaun

 

 

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to