Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 10 Dec 2004
Offline Last Active May 27 2016 05:48 AM

Posts I've Made

In Topic: Oh the begging

13 January 2016 - 09:03 AM

There's a non-profit organization called the Mozilla Foundation. It fully owns the commercial Mozilla Corporation and according to wikipedia it reinvests all profits into the foundation and its open source projects. I personally question wether there's a reason to preferr a non-profit vs for-profit organization when it comes to stuff like browsers, I go purely on user experience and technical merit.

In Topic: What programming languages does support VLAs?

08 January 2016 - 07:07 PM

It's a mix of OS and compiler support, though certain architecture features might make it easier (virtual memory in particular I guess?)

Even if your compiler and OS doesn't support it you can easily make your own. Even something as simple as an array of structs containing thread ID or handle and a pointer to the memory you're storing for that thread.

If only. smile.png There's no reliable API to get thread index. Possibly some thread pointer, but then you'd need a dictionary which is waaaay too slow and complex.

In Topic: What programming languages does support VLAs?

08 January 2016 - 02:13 PM

You can use thread-local storage which is supported by most compilers, and as of C++11 is part of the standard.

Whoa, I knew TLS existed but I had no idea it was part of the C++ standard. Unfortunately, C++ is not an option and TLS does AFAIK not exist for the platforms and compilers I need to support. sad.png

To be able to find a pool by pointer, I still need that first pointer which I'm afraid I don't have. Also, performance implications. A global "stack" with some form of synchronization would likely have performance implications in addition to what I can only imagine would be serious fragmentation problems which would require some form of cleanup step (again, performance).

In Topic: What programming languages does support VLAs?

08 January 2016 - 01:35 PM

So use a stack allocator per thread. That's what you are doing by using VLAs, anyway, since each thread has its own stack.

Not sure what you mean here? (honest question)

Are you talking about a pre-allocated (on heap) pool with stack like semantics? How could I do that without passing anything along to my function? Some compiler extension which allows per-thread globals?

Or are you talking about a stack-allocated buffer on each thread? Either we'd have to allocate it early on and pass it along, or we'd have to create the buffer each time we enter the function, but how would that be better than using a fixed-size array of worst case size?

Or are you talking about using some macro/whatever to manipulate the stack pointers explicitly? Would this be better than using compiler supported VLAs in some way? (again, honest question)

In Topic: What programming languages does support VLAs?

08 January 2016 - 08:45 AM

There's nothing to stop you pre-malloc'ing a large block of memory, and then using a stack (FIFO) allocator to allocate smaller arrays from that block. You've now amortised the cost of a single malloc call across all array allocations, and it's likely just as fast as using VLAs, since it too behaves like a stack.


Except it might not be thread safe and you might not have a suitable way to identify which thread you are on or be able to pass a thread local pool/heap-stack/whatever along. An example is a callback from a library, that might be called from multiple threads. In my case, it was an OS callback that was fired on (among others) malloc() and free(). The options were VLAs or always worst case.