Signature Description

struct  MemUsage  {
    size_t  column_used_memory { 0 };
    size_t  column_capacity_memory { 0 };
    size_t  column_type_size { 0 };
    size_t  index_used_memory { 0 };
    size_t  index_capacity_memory { 0 };
    size_t  index_type_size { 0 };

    template<typename S>
    friend S &operator << (S &stream, const MemUsage &mu);
}; 
        
This struct holds the result of calling get_memory_usage() method on DataFrame.

Signature Description Parameters

template<typename T>
[[nodiscard]] MemUsage
get_memory_usage(const char *col_name) const;
        
It returns the memory used by the given column and index column.
All numbers are in bytes.
MemUsage is a structure defined in DataFrameTypes.h file.
NOTE: The returned values are only estimates. The actual allocated memory by OS is unknown to any container object. In other words, the actual memory used might be and probably is larger than numbers returned by this call. Also if a type (T) allocates dynamic memory, it is not included in the result
T: Type of the col_name column.
col_name: Name of the column
static void test_get_view_by_loc()  {

    std::cout << "\nTesting get_view_by_loc() ..." << std::endl;

    std::vector<unsigned long>  idx = { 123450, 123451, 123452, 123450, 123455, 123450, 123449 };
    std::vector<double> d1 = { 1, 2, 3, 4, 5, 6, 7 };
    std::vector<double> d2 = { 8, 9, 10, 11, 12, 13, 14 };
    std::vector<double> d3 = { 15, 16, 17, 18, 19, 20, 21 };
    std::vector<double> d4 = { 22, 23, 24, 25 };
    std::vector<std::string> s1 = { "11", "22", "33", "xx", "yy", "gg", "string" };
    MyDataFrame         df;

    df.load_data(std::move(idx),
                 std::make_pair("col_1", d1),
                 std::make_pair("col_2", d2),
                 std::make_pair("col_3", d3),
                 std::make_pair("col_4", d4),
                 std::make_pair("col_str", s1));

    auto  memory_use1 = df.get_memory_usage<double>("col_3");

    std::cout << "DataFrame Memory Usage:\n" << memory_use1 << std::endl;

    typedef DataFrameView<unsigned long> MyDataFrameView;

    MyDataFrameView dfv = df.get_view_by_loc<double, std::string>(Index2D<long> { 3, 6 });

    dfv.shrink_to_fit<double, std::string>();
    dfv.write<std::ostream, double, std::string>(std::cout);
    dfv.get_column<double>("col_3")[0] = 88.0;
    assert(dfv.get_column<double>("col_3")[0] == df.get_column<double>("col_3")[3]);
    assert(dfv.get_column<double>("col_3")[0] == 88.0);

    auto  memory_use2 = dfv.get_memory_usage<double>("col_3");

    std::cout << "View Memory Usage:\n" << memory_use2 << std::endl;
}
C++ DataFrame