FACT++  1.0
void * Memory::malloc ( )

Definition at line 99 of file EventBuilder.cc.

References g_maxMem, inuse, and MAX_TOT_MEM.

Referenced by add_char_item_node(), add_exit_handler(), add_exit_handler_item(), add_int_item_node(), add_item_node(), ast_conn_h(), check_browser_changes(), client_info(), command_handler(), create_browser(), create_client(), create_dns(), createBenchmark(), createCharItem(), createHeader(), createIntItem(), createItem(), createMemoryNode(), dic_add_dns(), dic_get_server_services(), dic_release_service(), did_prepare_command(), dim_dtq_init(), dis_add_dns(), dis_dns_init(), dis_get_client_services(), dis_get_next_cmnd(), dis_hash_service_init(), dis_hash_service_insert(), dis_insert_request(), dis_send_service(), dis_set_buffer_size(), dis_set_client_exit_handler(), dis_start_serving_dns(), dna_open_client(), dna_write(), do_dis_add_cmnd_dns(), do_dis_add_service_dns(), do_got_service_list(), dtq_add_entry(), dtq_create(), dummy_alrm_sig_handler(), enable_sig(), execute_command(), execute_service(), fillCharItem(), fillIntItem(), fillItem(), find_services(), findSmiServices(), get_new_dns_server_info(), getDeadband(), getIssueTimeout(), getLogLevel(), getUpdateRate(), got_service_list(), got_update_services(), got_update_smi_objects(), handle_client_request(), handle_dns_info(), handle_registration(), init_dns_list(), initialize(), EVT_CTRL2::initMemory(), insert_service(), Java_dim_MutableMemory_allocateNativeDataBlock(), Java_dim_ObjectDescriptor_newObjectDescriptor(), marshallHeader(), modify_service(), prepareJSONServiceList(), prepareJSONSmiObjectList(), prepareJSONSmiTree(), prepareJSONTree(), publish(), publishChar(), publishInt(), recv_service_info(), remove_service(), request_command(), request_service(), send_command(), send_dns_server_info(), send_service(), service_info(), service_init(), set_rpc_info(), setDeadband(), show_clients(), start(), std_cmnd_handler(), unescape(), update_servers(), update_service_data(), and updateFeeService().

100  {
101  // No free slot available, next alloc would exceed max memory
102  if (memory.empty() && allocated+MAX_TOT_MEM>g_maxMem)
103  return NULL;
104 
105  // We will return this amount of memory
106  // This is not 100% thread safe, but it is not a super accurate measure anyway
107  inuse += MAX_TOT_MEM;
108  if (inuse>max_inuse)
109  max_inuse = inuse;
110 
111  if (memory.empty())
112  {
113  // No free slot available, allocate a new one
115  return new char[MAX_TOT_MEM];
116  }
117 
118  // Get the next free slot from the stack and return it
119  const std::lock_guard<std::mutex> lock(mtx);
120 
121  void *mem = memory.front();
122  memory.pop_front();
123  return mem;
124  };
std::mutex mtx
Definition: EventBuilder.cc:95
std::forward_list< void * > memory
Definition: EventBuilder.cc:97
size_t g_maxMem
Definition: EventBuilder.cc:76
uint64_t inuse
Definition: EventBuilder.cc:90
uint64_t max_inuse
Definition: EventBuilder.cc:93
uint64_t allocated
Definition: EventBuilder.cc:91
#define MAX_TOT_MEM
Definition: EventBuilder.h:96