Skip to content

Commit

Permalink
Replace global balance arrays with std::map
Browse files Browse the repository at this point in the history
1. Doesn't cover full range of potential properties, can result in out-of-bounds violation
2. No need to reserve 100000 elements each
3. [] operator reads an element at position, if key exists, or inserts an element, if not
4. Balances are int64_t
  • Loading branch information
dexX7 committed May 15, 2015
1 parent 55b309d commit 25b6cb4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
12 changes: 8 additions & 4 deletions src/mastercore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,14 @@ static const int nBlockTop = 0;
static int nWaterlineBlock = 0; //

uint64_t global_metadex_market;
uint64_t global_balance_money_maineco[100000];
uint64_t global_balance_reserved_maineco[100000];
uint64_t global_balance_money_testeco[100000];
uint64_t global_balance_reserved_testeco[100000];
//! Available balances of wallet properties in the main ecosystem
std::map<uint32_t, int64_t> global_balance_money_maineco;
//! Reserved balances of wallet properties in the main ecosystem
std::map<uint32_t, int64_t> global_balance_reserved_maineco;
//! Available balances of wallet properties in the test ecosystem
std::map<uint32_t, int64_t> global_balance_money_testeco;
//! Reserved balances of wallet properties in the test ecosystem
std::map<uint32_t, int64_t> global_balance_reserved_testeco;

/**
* Used to indicate, whether to automatically commit created transactions.
Expand Down
14 changes: 8 additions & 6 deletions src/mastercore.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,15 @@ class CMPPending

};

//temp - only supporting 100,000 properties per eco here, research best way to expand array
//these 4 arrays use about 3MB total memory with 100K properties limit (100000*8*4 bytes)
extern uint64_t global_metadex_market;
extern uint64_t global_balance_money_maineco[100000];
extern uint64_t global_balance_reserved_maineco[100000];
extern uint64_t global_balance_money_testeco[100000];
extern uint64_t global_balance_reserved_testeco[100000];
//! Available balances of wallet properties in the main ecosystem
extern std::map<uint32_t, int64_t> global_balance_money_maineco;
//! Reserved balances of wallet properties in the main ecosystem
extern std::map<uint32_t, int64_t> global_balance_reserved_maineco;
//! Available balances of wallet properties in the test ecosystem
extern std::map<uint32_t, int64_t> global_balance_money_testeco;
//! Reserved balances of wallet properties in the test ecosystem
extern std::map<uint32_t, int64_t> global_balance_reserved_testeco;

int64_t getMPbalance(const string &Address, unsigned int property, TallyType ttype);
int64_t getUserAvailableMPbalance(const string &Address, unsigned int property);
Expand Down
5 changes: 0 additions & 5 deletions src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@
#define DECORATION_SIZE 64
#define NUM_ITEMS 6 // 3 - number of recent transactions to display

extern uint64_t global_balance_money_maineco[100000];
extern uint64_t global_balance_reserved_maineco[100000];
extern uint64_t global_balance_money_testeco[100000];
extern uint64_t global_balance_reserved_testeco[100000];

class TxViewDelegate : public QAbstractItemDelegate
{
Q_OBJECT
Expand Down

0 comments on commit 25b6cb4

Please sign in to comment.