Skip to content

Commit

Permalink
Revert "lets try this"
Browse files Browse the repository at this point in the history
This reverts commit 379133b.
  • Loading branch information
cyrush committed Jul 15, 2021
1 parent 379133b commit 66558d3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 88 deletions.
33 changes: 0 additions & 33 deletions src/libs/conduit/conduit_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16175,39 +16175,6 @@ Node::mmap(const std::string &stream_path, index_t data_size)
m_mmaped = true;
}

//-----------------------------------------------------------------------------
void *
default_alloc_handler(size_t items, size_t item_size)
{
return calloc(items, item_size);
}

//-----------------------------------------------------------------------------
void
default_free_handler(void *data_ptr)
{
free(data_ptr);
}

//-----------------------------------------------------------------------------
std::map<index_t,void*(*)(size_t, size_t)> &
Node::allocator_map()
{
static std::map<index_t,void*(*)(size_t, size_t)> _allocator_map
= {{0, &default_alloc_handler}};
return _allocator_map;
}

//-----------------------------------------------------------------------------
std::map<index_t,void(*)(void*)> &
Node::free_map()
{
//-----------------------------------------------------------------------------
static std::map<index_t,void(*)(void*)> _free_map
= {{0, default_free_handler}};
return _free_map;
}


//---------------------------------------------------------------------------//
void
Expand Down
7 changes: 0 additions & 7 deletions src/libs/conduit/conduit_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4313,13 +4313,6 @@ class CONDUIT_API Node
void allocate(const DataType &dtype);
void mmap(const std::string &stream_path,
index_t dsize);
//-------------------------------------------------------------------------
// private memory manager static maps for registered allocators
//-------------------------------------------------------------------------
public:
static std::map<index_t,void*(*)(size_t, size_t)> &allocator_map();
static std::map<index_t,void(*)(void*)> &free_map();
private:
// release any alloced or memory mapped data
void release();
// clean up everything (used by destructor)
Expand Down
79 changes: 31 additions & 48 deletions src/libs/conduit/conduit_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ namespace conduit
namespace utils
{

// //-----------------------------------------------------------------------------
// void *
// default_alloc_handler(size_t items, size_t item_size)
// {
// return calloc(items, item_size);
// }
//
// //-----------------------------------------------------------------------------
// void
// default_free_handler(void *data_ptr)
// {
// free(data_ptr);
// }
//-----------------------------------------------------------------------------
void *
default_alloc_handler(size_t items, size_t item_size)
{
return calloc(items, item_size);
}

//-----------------------------------------------------------------------------
void
default_free_handler(void *data_ptr)
{
free(data_ptr);
}

//-----------------------------------------------------------------------------
void
Expand Down Expand Up @@ -135,48 +135,31 @@ set_memset_handler(void(*conduit_hnd_memset)(void*,
conduit_handle_memset = conduit_hnd_memset;
}

class AllocMap
//-----------------------------------------------------------------------------
static std::map<index_t,void*(*)(size_t, size_t)> &allocator_map()
{
friend class Node;

public:
static std::map<index_t,void*(*)(size_t, size_t)> &allocator_map()
{
return Node::allocator_map();
}

static std::map<index_t,void(*)(void*)> &free_map()
{
return Node::free_map();
}

};
static std::map<index_t,void*(*)(size_t, size_t)> _allocator_map
= {{0, &default_alloc_handler}};
return _allocator_map;
}

// //-----------------------------------------------------------------------------
// static std::map<index_t,void*(*)(size_t, size_t)> &allocator_map()
// {
// static std::map<index_t,void*(*)(size_t, size_t)> _allocator_map
// = {{0, &default_alloc_handler}};
// return _allocator_map;
// }
//
// //-----------------------------------------------------------------------------
// static std::map<index_t,void(*)(void*)> &free_map()
// {
// //-----------------------------------------------------------------------------
// static std::map<index_t,void(*)(void*)> _free_map
// = {{0, default_free_handler}};
// return _free_map;
// }
//-----------------------------------------------------------------------------
static std::map<index_t,void(*)(void*)> &free_map()
{
//-----------------------------------------------------------------------------
static std::map<index_t,void(*)(void*)> _free_map
= {{0, default_free_handler}};
return _free_map;
}

//-----------------------------------------------------------------------------
index_t
register_allocator(void*(*conduit_hnd_allocate) (size_t, size_t),
void(*conduit_hnd_free)(void *))
{
static index_t allocator_id = 1;
AllocMap::allocator_map()[allocator_id] = conduit_hnd_allocate;
AllocMap::free_map()[allocator_id] = conduit_hnd_free;
allocator_map()[allocator_id] = conduit_hnd_allocate;
free_map()[allocator_id] = conduit_hnd_free;
return allocator_id++;
}

Expand All @@ -187,15 +170,15 @@ conduit_allocate(size_t n_items,
size_t item_size,
index_t allocator_id)
{
return AllocMap::allocator_map()[allocator_id](n_items, item_size);
return allocator_map()[allocator_id](n_items, item_size);
}

//-----------------------------------------------------------------------------
void
conduit_free(void *ptr,
index_t allocator_id)
{
AllocMap::free_map()[allocator_id](ptr);
free_map()[allocator_id](ptr);
}

//-----------------------------------------------------------------------------
Expand Down

0 comments on commit 66558d3

Please sign in to comment.