#109 Using Poco::Dynamic::Var with custom VarHolder implementati

Unstable_(example)
pending
None
5
2012-10-01
2012-07-06
Marian Krivos
No

This patch add simple one line constructor to the Poco::Dynamic::Var class to allow using this class with your own VarHolder. These customised implementation can use different storage policy or/and basic types. By example for small strings up to 7+1 bytes you can implement VarHolder without pointer but char[8] storage which effectively saves some bytes on 64bit machines etc.

Simple memory benchmark with 10.000.000 strings with size 7+1 bytes
Benchmark results (64bit linux, gcc 4.6.3):

Plain malloc(string + pointers to each) = 383MB of memory occupied
Standard Var with std::string storage + pointers to each = 839 of memory occupied
Customized Var with embedded char[8] storage + pointers to each = 687 of memory occupied

Discussion

  • Marian Krivos
    Marian Krivos
    2012-07-06

     
    Attachments
  • Alex Fabijanic
    Alex Fabijanic
    2012-07-07

    This is definitely interesting. Could you submit your benchmark so we can add it as a sample for the next release?

     
  • Marian Krivos
    Marian Krivos
    2012-07-07

     
    Attachments
  • Marian Krivos
    Marian Krivos
    2012-07-07

    Simple benchmark added.

     
  • Alex Fabijanic
    Alex Fabijanic
    2012-10-01

    I looked into this; it is definitely an interesting idea but the benchmark only measures time, not the amount of memory used.

    What I'd like to see before we add this feature is a more general partial-specialization based solution, something along these lines (note: not compiled, just brainstorming late at night):

    in VarHolder.h:

    template <typename T, unsigned N = 0>
    class VarHolderImpl: public VarHolder
    { ... }

    template <typename T, unsigned N>
    class VarHolderImpl<T*, N>: public VarHolder
    {
    ...
    T& operator [] (index);
    T* _val;
    }

    then user can do this:

    typedef VarHolderImpl<char*,8> VarHolderChar8;

    That would be something I'd be interested in and willing to add to the library.

     
    Last edit: Alex Fabijanic 2012-10-01
  • Alex Fabijanic
    Alex Fabijanic
    2012-10-01

    • status: open --> pending
    • milestone: --> Unstable_(example)