Skip to content

Commit

Permalink
Merge pull request #1995 from steemit/1984-std-allocator
Browse files Browse the repository at this point in the history
1984 std allocator
  • Loading branch information
Michael Vandeberg authored Mar 14, 2018
2 parents 71cc1a8 + ffd4ff9 commit 22bfb47
Show file tree
Hide file tree
Showing 19 changed files with 269 additions and 79 deletions.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ if( ENABLE_SMT_SUPPORT )
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSTEEM_ENABLE_SMT" )
endif()

OPTION( ENABLE_STD_ALLOCATOR_SUPPORT "Build source with STD allocator (ON OR OFF)" OFF )
MESSAGE( STATUS "ENABLE_STD_ALLOCATOR_SUPPORT: ${ENABLE_STD_ALLOCATOR_SUPPORT}" )
if( ENABLE_STD_ALLOCATOR_SUPPORT )
MESSAGE( STATUS " " )
MESSAGE( STATUS " CONFIGURING FOR STD ALLOCATOR " )
MESSAGE( STATUS " " )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_STD_ALLOCATOR" )
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DENABLE_STD_ALLOCATOR" )
endif()

OPTION( LOW_MEMORY_NODE "Build source for low memory node (ON OR OFF)" OFF )
MESSAGE( STATUS "LOW_MEMORY_NODE: ${LOW_MEMORY_NODE}" )
if( LOW_MEMORY_NODE )
Expand Down Expand Up @@ -315,6 +325,12 @@ else()
MESSAGE( STATUS "\n\n CONFIGURED FOR NO SUPPORT OF SMT \n\n" )
endif()

if( ENABLE_STD_ALLOCATOR_SUPPORT )
MESSAGE( STATUS "\n\n CONFIGURED FOR STD ALLOCATOR SUPPORT \n\n" )
else()
MESSAGE( STATUS "\n\n CONFIGURED FOR NO SUPPORT OF STD ALLOCATOR \n\n" )
endif()

if( LOW_MEMORY_NODE )
MESSAGE( STATUS "\n\n CONFIGURED FOR LOW MEMORY NODE \n\n" )
else()
Expand Down
4 changes: 4 additions & 0 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ const comment_object* database::find_comment( const account_name_type& author, c
return find< comment_object, by_permlink >( boost::make_tuple( author, permlink ) );
}

#ifndef ENABLE_STD_ALLOCATOR
const comment_object& database::get_comment( const account_name_type& author, const string& permlink )const
{ try {
return get< comment_object, by_permlink >( boost::make_tuple( author, permlink) );
Expand All @@ -428,6 +429,7 @@ const comment_object* database::find_comment( const account_name_type& author, c
{
return find< comment_object, by_permlink >( boost::make_tuple( author, permlink ) );
}
#endif

const escrow_object& database::get_escrow( const account_name_type& name, uint32_t escrow_id )const
{ try {
Expand Down Expand Up @@ -2617,7 +2619,9 @@ void database::apply_block( const signed_block& next_block, uint32_t skip )
}
}

#ifndef ENABLE_STD_ALLOCATOR
show_free_memory( false, next_block.block_num() );
#endif

} FC_CAPTURE_AND_RETHROW( (next_block) ) }

Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/include/steem/chain/account_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ namespace steem { namespace chain {
public:
template< typename Constructor, typename Allocator >
owner_authority_history_object( Constructor&& c, allocator< Allocator > a )
:previous_owner_authority( shared_authority::allocator_type( a.get_segment_manager() ) )
:previous_owner_authority( allocator< shared_authority >( a ) )
{
c( *this );
}
Expand All @@ -206,7 +206,7 @@ namespace steem { namespace chain {
public:
template< typename Constructor, typename Allocator >
account_recovery_request_object( Constructor&& c, allocator< Allocator > a )
:new_owner_authority( shared_authority::allocator_type( a.get_segment_manager() ) )
:new_owner_authority( allocator< shared_authority >( a ) )
{
c( *this );
}
Expand Down
4 changes: 3 additions & 1 deletion libraries/chain/include/steem/chain/buffer_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace steem { namespace chain {

typedef chainbase::bip::vector< char, chainbase::allocator< char > > buffer_type;
typedef chainbase::t_vector< char > buffer_type;

} } // steem::chain

Expand Down Expand Up @@ -37,4 +37,6 @@ template< typename T > inline T unpack_from_buffer( const steem::chain::buffer_t

} } // fc::raw

#ifndef ENABLE_STD_ALLOCATOR
FC_REFLECT_TYPENAME( steem::chain::buffer_type )
#endif
8 changes: 6 additions & 2 deletions libraries/chain/include/steem/chain/comment_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace steem { namespace chain {

using protocol::beneficiary_route_type;
using chainbase::t_vector;

struct strcmp_less
{
Expand All @@ -20,6 +21,7 @@ namespace steem { namespace chain {
return less( a.c_str(), b.c_str() );
}

#ifndef ENABLE_STD_ALLOCATOR
bool operator()( const shared_string& a, const string& b )const
{
return less( a.c_str(), b.c_str() );
Expand All @@ -29,6 +31,7 @@ namespace steem { namespace chain {
{
return less( a.c_str(), b.c_str() );
}
#endif

private:
inline bool less( const char* a, const char* b )const
Expand Down Expand Up @@ -95,8 +98,9 @@ namespace steem { namespace chain {
bool allow_votes = true; /// allows a post to receive votes;
bool allow_curation_rewards = true;

typedef bip::vector< beneficiary_route_type, allocator< beneficiary_route_type > > t_beneficiaries;
t_beneficiaries beneficiaries;
using t_beneficiaries = t_vector< beneficiary_route_type >;

t_beneficiaries beneficiaries;
};

class comment_content_object : public object< comment_content_object_type, comment_content_object >
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/steem/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ namespace steem { namespace chain {
const comment_object& get_comment( const account_name_type& author, const shared_string& permlink )const;
const comment_object* find_comment( const account_name_type& author, const shared_string& permlink )const;

#ifndef ENABLE_STD_ALLOCATOR
const comment_object& get_comment( const account_name_type& author, const string& permlink )const;
const comment_object* find_comment( const account_name_type& author, const string& permlink )const;
#endif

const escrow_object& get_escrow( const account_name_type& name, uint32_t escrow_id )const;
const escrow_object* find_escrow( const account_name_type& name, uint32_t escrow_id )const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@

namespace steem { namespace chain {

using chainbase::t_vector;

class hardfork_property_object : public object< hardfork_property_object_type, hardfork_property_object >
{
public:
template< typename Constructor, typename Allocator >
hardfork_property_object( Constructor&& c, allocator< Allocator > a )
:processed_hardforks( a.get_segment_manager() )
:processed_hardforks( a )
{
c( *this );
}

id_type id;

bip::vector< fc::time_point_sec, allocator< fc::time_point_sec > > processed_hardforks;
using t_processed_hardforks = t_vector< fc::time_point_sec >;

t_processed_hardforks processed_hardforks;
uint32_t last_hardfork = 0;
protocol::hardfork_version current_hardfork_version;
protocol::hardfork_version next_hardfork;
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/steem/chain/history_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace steem { namespace chain {
public:
template< typename Constructor, typename Allocator >
operation_object( Constructor&& c, allocator< Allocator > a )
:serialized_op( a.get_segment_manager() )
:serialized_op( a )
{
c( *this );
}
Expand Down
32 changes: 16 additions & 16 deletions libraries/chain/include/steem/chain/shared_authority.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <steem/protocol/authority.hpp>
#include <chainbase/chainbase.hpp>
#include <boost/interprocess/managed_mapped_file.hpp>

namespace steem { namespace chain {
Expand All @@ -8,7 +9,8 @@ namespace steem { namespace chain {
using steem::protocol::account_name_type;
using steem::protocol::weight_type;

namespace bip = boost::interprocess;
using chainbase::t_flat_map;
using chainbase::t_allocator_pair;

/**
* The purpose of this class is to represent an authority object in a manner compatiable with
Expand All @@ -24,8 +26,8 @@ namespace steem { namespace chain {

template< typename Allocator >
shared_authority( const authority& a, const Allocator& alloc ) :
account_auths( account_pair_allocator_type( alloc.get_segment_manager() ) ),
key_auths( key_pair_allocator_type( alloc.get_segment_manager() ) )
account_auths( account_pair_allocator_type( alloc ) ),
key_auths( key_pair_allocator_type( alloc ) )
{
account_auths.reserve( a.account_auths.size() );
key_auths.reserve( a.key_auths.size() );
Expand All @@ -42,14 +44,14 @@ namespace steem { namespace chain {

template< typename Allocator >
shared_authority( const Allocator& alloc ) :
account_auths( account_pair_allocator_type( alloc.get_segment_manager() ) ),
key_auths( key_pair_allocator_type( alloc.get_segment_manager() ) ) {}
account_auths( account_pair_allocator_type( alloc ) ),
key_auths( key_pair_allocator_type( alloc ) ) {}

template< typename Allocator, class ...Args >
shared_authority( const Allocator& alloc, uint32_t weight_threshold, Args... auths ) :
weight_threshold( weight_threshold ),
account_auths( account_pair_allocator_type( alloc.get_segment_manager() ) ),
key_auths( key_pair_allocator_type( alloc.get_segment_manager() ) )
account_auths( account_pair_allocator_type( alloc ) ),
key_auths( key_pair_allocator_type( alloc ) )
{
add_authorities( auths... );
}
Expand Down Expand Up @@ -81,17 +83,15 @@ namespace steem { namespace chain {
void clear();
void validate()const;

typedef bip::allocator< shared_authority, bip::managed_mapped_file::segment_manager > allocator_type;
using account_pair_allocator_type = t_allocator_pair< account_name_type, weight_type >;
using key_pair_allocator_type = t_allocator_pair< public_key_type, weight_type >;

typedef bip::allocator< std::pair< account_name_type, weight_type >, bip::managed_mapped_file::segment_manager > account_pair_allocator_type;
typedef bip::allocator< std::pair< public_key_type, weight_type >, bip::managed_mapped_file::segment_manager > key_pair_allocator_type;
typedef t_flat_map< account_name_type, weight_type> account_authority_map;
typedef t_flat_map< public_key_type, weight_type> key_authority_map;

typedef bip::flat_map< account_name_type, weight_type, std::less< account_name_type >, account_pair_allocator_type > account_authority_map;
typedef bip::flat_map< public_key_type, weight_type, std::less< public_key_type >, key_pair_allocator_type > key_authority_map;

uint32_t weight_threshold = 0;
account_authority_map account_auths;
key_authority_map key_auths;
uint32_t weight_threshold = 0;
account_authority_map account_auths;
key_authority_map key_auths;
};

bool operator == ( const shared_authority& a, const shared_authority& b );
Expand Down
19 changes: 17 additions & 2 deletions libraries/chain/include/steem/chain/steem_object_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include <steem/protocol/types.hpp>
#include <steem/protocol/authority.hpp>

#include <steem/chain/buffer_type.hpp>

namespace steem { namespace chain {

namespace bip = chainbase::bip;
using namespace boost::multi_index;

using boost::multi_index_container;
Expand All @@ -27,7 +27,8 @@ using steem::protocol::chain_id_type;
using steem::protocol::account_name_type;
using steem::protocol::share_type;

typedef bip::basic_string< char, std::char_traits< char >, allocator< char > > shared_string;
using chainbase::shared_string;

inline std::string to_string( const shared_string& str ) { return std::string( str.begin(), str.end() ); }
inline void from_string( shared_string& out, const string& in ){ out.assign( in.begin(), in.end() ); }

Expand Down Expand Up @@ -190,6 +191,18 @@ namespace fc
{
s.read( (char*)&id._id, sizeof(id._id));
}
#ifndef ENABLE_STD_ALLOCATOR
template< typename T >
inline T unpack_from_vector( const steem::chain::buffer_type& s )
{ try {
T tmp;
if( s.size() ) {
datastream<const char*> ds( s.data(), size_t(s.size()) );
fc::raw::unpack(ds,tmp);
}
return tmp;
} FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
#endif
}
}

Expand Down Expand Up @@ -231,6 +244,8 @@ FC_REFLECT_ENUM( steem::chain::object_type,
#endif
)

#ifndef ENABLE_STD_ALLOCATOR
FC_REFLECT_TYPENAME( steem::chain::shared_string )
#endif

FC_REFLECT_ENUM( steem::chain::bandwidth_type, (post)(forum)(market) )
8 changes: 6 additions & 2 deletions libraries/chain/include/steem/chain/steem_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace steem { namespace chain {
using steem::protocol::asset;
using steem::protocol::price;
using steem::protocol::asset_symbol_type;
using chainbase::t_deque;

typedef protocol::fixed_string< 16 > reward_fund_name_type;

Expand Down Expand Up @@ -158,15 +159,18 @@ namespace steem { namespace chain {
public:
template< typename Constructor, typename Allocator >
feed_history_object( Constructor&& c, allocator< Allocator > a )
:price_history( a.get_segment_manager() )
:price_history( a )
{
c( *this );
}

id_type id;

price current_median_history; ///< the current median of the price history, used as the base for convert operations
bip::deque< price, allocator< price > > price_history; ///< tracks this last week of median_feed one per hour

using t_price_history = t_deque< price >;

t_deque< price > price_history; ///< tracks this last week of median_feed one per hour
};


Expand Down
1 change: 1 addition & 0 deletions libraries/chain/include/steem/chain/transaction_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace steem { namespace chain {

using steem::protocol::signed_transaction;
using chainbase::t_vector;

/**
* The purpose of this object is to enable the detection of duplicate transactions. When a transaction is included
Expand Down
Loading

0 comments on commit 22bfb47

Please sign in to comment.