[array] Construct a variable-length array with "alloca"

Dear boost interesters: "alloca" maybe a suitable tool to construct a variable-length array. The attachment demonstrates the class for variable-length array, most of the codes in which are copied from original "array.hpp" in boost libraries. Hope it is useful. Regards, xhchen =========================================================================================== The privileged confidential information contained in this email is intended for use only by the addressees as indicated by the original sender of this email. If you are not the addressee indicated in this email or are not responsible for delivery of the email to such a person, please kindly reply to the sender indicating this fact and delete all copies of it from your computer and network server immediately. Your cooperation is highly appreciated. It is advised that any unauthorized use of confidential information of Winbond is strictly prohibited; and any information in this email irrelevant to the official business of Winbond shall be deemed as neither given nor endorsed by Winbond.

On 10/18/06, XHChen@winbond.com <XHChen@winbond.com> wrote:
Dear boost interesters:
"alloca" maybe a suitable tool to construct a variable-length array. The attachment demonstrates the class for variable-length array, most of the codes in which are copied from original "array.hpp" in boost libraries. Hope it is useful.
I was thinking of something like that just yesterday (that is, the way to have dynamically sized automatic arrays). The problem of your solution is that it uses alloca, and this function is not defined by any standard (not only it is not in C nor C++, neither POSIX and SuS define it). There is no portable way to dynamically allocate space on the standard stack, but the fact is, there is really no reason that we must use the standard stack. The idea is that the alloca is fast because you just need to increase the SP pointer to allocate memory, but you can do that with any stack. Have a global alternate stack (better if it is thread local) and use it to allocate 'stacked' space. In practice your custom alloca would allocate from it instead of the 'real stack'. If you want to wrap it under an allocator interface, push_allocate and pop_deallocate would be good names. This solution would have the same allocation speed of the historical alloca and probably the same cache locality. If you relax the condition that allocation and deallocaiton must be strictly FIFO (i.e. you can temporarily waste memroy while a free space is blocked by an allocated chunk above it), you could even make it a standard allocator. HTH, Giovanni P. Deretta

Yes, it definitely would. So do not make it movable. On 10/19/06, loufoque <mathias.gaunard@etu.u-bordeaux1.fr> wrote:
Giovanni Piero Deretta wrote:
you could even make it a standard allocator.
Won't something based on alloca be broken with move semantics, where you don't copy the underlying buffer?
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (3)
-
Giovanni Piero Deretta
-
loufoque
-
XHChen@winbond.com