User: Password:
|
|
Subscribe / Log in / New account

MSVC

MSVC

Posted Mar 11, 2013 15:21 UTC (Mon) by nix (subscriber, #2304)
In reply to: MSVC by Cyberax
Parent article: Michaelsen: One

I'm reasonably certain that nobody who was talking about constexprs with reference to compile-time calculation could possibly have thought that you could allocate memory or file handles at compile time. That's ridiculous.


(Log in to post comments)

MSVC

Posted Mar 11, 2013 15:24 UTC (Mon) by Cyberax (✭ supporter ✭, #52523) [Link]

So what kind of calculations you can do in constexprs that could noticeably reduce app startup time? I'm totally at loss here.

Almost all more-or-less complex algorithms require something that is not really possible with constexprs.

MSVC

Posted Mar 11, 2013 16:52 UTC (Mon) by etienne (guest, #25256) [Link]

> So what kind of calculations you can do in constexprs that could noticeably reduce app startup time?

If you have a very long list of parameters with plenty of sub-parameters (kind of 4096 channels with 50+ configuration options and their SNMP descriptors), you can have them pre-organised (with their next/previous fields pre-initialised) if you declare them "static" and not malloced.
Or if you have a long dictionary.

Note that you could try to support malloc/free inside constexprs by having another section in your ELF file (like .data but after .bss), so that the malloc/free functions (either in glibc or your own wrapper) do not start empty but call brk()/sbrk() to increase that new section... should work at least on Linux (excluding LD_PRELOAD of another malloc/free library).

MSVC

Posted Mar 11, 2013 17:29 UTC (Mon) by Cyberax (✭ supporter ✭, #52523) [Link]

> If you have a very long list of parameters with plenty of sub-parameters (kind of 4096 channels with 50+ configuration options and their SNMP descriptors), you can have them pre-organised (with their next/previous fields pre-initialised) if you declare them "static" and not malloced.
Not really. You'll be able to initialize the 'prev' pointers. But you can do this just fine with the current static init.

> Or if you have a long dictionary.
Compile-time? I doubt it. Though you probably could with lots of template magic.

>Note that you could try to support malloc/free inside constexprs by having another section in your ELF file (like .data but after .bss), so that the malloc/free functions (either in glibc or your own wrapper) do not start empty but call brk()/sbrk() to increase that new section
No you can't. Standard explicitly forbids any pointer math that might result in addresses outside of _initialized_ static storage.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds