How to serialize numeric data into char*
I have a need to serialize `int, double, long, and float`
into a character buffer and this is the way I currently do it<br>


    int value = 42;
    char* data = new char[64];
    std::sprintf(data, "%d", value);
    
    // check
    printf( "%s\n", data );

First I am not sure if this is the best way to do it but my immediate problem is determining the size of the buffer.<br> The number 64 in this case is purely arbitrary.
How can I know the exact size of the passed numeric so I can allocate exact memory; not more not less than is required? <br>

Either a C or C++ solution is fine.

How to serialize numeric data into char*
===

I have a need to serialize `int, double, long, and float`
into a character buffer and this is the way I currently do it<br>


    int value = 42;
    char* data = new char[64];
    std::sprintf(data, "%d", value);
    
    // check
    printf( "%s\n", data );

First I am not sure if this is the best way to do it but my immediate problem is determining the size of the buffer.<br> The number 64 in this case is purely arbitrary.
How can I know the exact size of the passed numeric so I can allocate exact memory; not more not less than is required? <br>

Either a C or C++ solution is fine.
