MCPcopy Create free account
hub / github.com/davisking/dlib / main

Function main

examples/std_allocator_ex.cpp:25–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24
25int main()
26{
27 // Make a typedef for an allocator that uses the thread safe memory_manager_stateless object with a
28 // global memory pool. This version of the memory_manager_stateless object keeps everything it allocates
29 // in a global memory pool and doesn't release any memory until the program terminates.
30 typedef std_allocator<char, memory_manager_stateless<char>::kernel_2_3a> alloc_char_with_global_memory_pool;
31
32 // Now make a typedef for a C++ standard string that uses our new allocator type
33 typedef std::basic_string<char, char_traits<char>, alloc_char_with_global_memory_pool > dstring;
34
35
36 // typedef another allocator for dstring objects
37 typedef std_allocator<dstring, memory_manager_stateless<char>::kernel_2_3a> alloc_dstring_with_global_memory_pool;
38
39 // Now make a typedef for a C++ standard vector that uses our new allocator type and also contains the new dstring
40 typedef std::vector<dstring, alloc_dstring_with_global_memory_pool > dvector;
41
42 // Now we can use the string and vector we have as we normally would. So for example, I can make a
43 // dvector and add 4 strings into it like so:
44 dvector v;
45 v.push_back("one");
46 v.push_back("two");
47 v.push_back("three");
48 v.push_back("four");
49
50 // And now we print out the contents of our vector
51 for (unsigned long i = 0; i < v.size(); ++i)
52 {
53 cout << v[i] << endl;
54 }
55
56}
57

Callers

nothing calls this directly

Calls 2

push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected