Skip to content

Commit

Permalink
Updated SharedGcPtr. Removed stl_allocator interface - Closes #47.
Browse files Browse the repository at this point in the history
  • Loading branch information
m4drat committed May 28, 2022
1 parent 05a104d commit 74185a9
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 146 deletions.
16 changes: 0 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ option(MPP_USE_FUZZER_DEFINITIONS "Build mpp with fuzzing-friendly defines" OFF)
option(MPP_BUILD_EXAMPLE "Build mpp example project" ON)
option(MPP_BUILD_TESTS "Build mpp tests" ON)
option(MPP_BUILD_DOCS "Build mpp documentation" OFF)
option(MPP_BUILD_BENCHMARKS "Build mpp benchmark (tcmalloc, jemalloc, malloc, mpp)" ON)
option(CMAKE_EXPORT_COMPILE_COMMANDS "Request generate of json file with all build commands" ON)

message(STATUS "##################### GLOBAL OPTIONS #####################")
Expand All @@ -34,7 +33,6 @@ message(STATUS "MPP_USE_FUZZER_DEFINITIONS : ${MPP_USE_FUZZER_DEFINITIONS}")
message(STATUS "MPP_BUILD_EXAMPLE : ${MPP_BUILD_EXAMPLE}")
message(STATUS "MPP_BUILD_TESTS : ${MPP_BUILD_TESTS}")
message(STATUS "MPP_BUILD_DOCS : ${MPP_BUILD_DOCS}")
message(STATUS "MPP_BUILD_BENCHMARKS : ${MPP_BUILD_BENCHMARKS}")

################# ADD PROJECTS + DOCS + TESTS #################
add_subdirectory(libmemplusplus)
Expand Down Expand Up @@ -74,19 +72,5 @@ if (MPP_BUILD_DOCS)
add_subdirectory(docs)
endif()

if (MPP_BUILD_BENCHMARKS)
include_directories("libraries")

message(STATUS "[+] Building with benchmark")
enable_testing()

add_subdirectory(libraries/googletest)
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Disable google benchmark tests" FORCE)
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable google benchmark tests" FORCE)
add_subdirectory(libraries/benchmark)

add_subdirectory(memplusplus-benchmarks)
endif()

################# CLANG FORMAT / CLANG-TIDY #################
include(cmake/clang-cxx-dev-tools.cmake)
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ Current library version: 2.3.5

1. Install latest build systems: `apt install cmake g++ clang`
2. Clone just the library: `git clone https://github.com/m4drat/memplusplus/`
3. Clone the library (with benchmarks and tests support): `git clone --recurse-submodules https://github.com/m4drat/memplusplus/`
4. Clone the library (with tests support): `git clone --recurse-submodules=./libraries/Catch2 https://github.com/m4drat/memplusplus/`
3. Clone the library (with tests support): `git clone --recurse-submodules=./libraries/Catch2 https://github.com/m4drat/memplusplus/`
4. Benchmarks (can be found in separate git repo): `git clone https://github.com/m4drat/memplusplus-benchmarks`
1. Run them as follows: `cd memplusplus-benchmarks && ./run_all.sh`

### How to use the library as a dependency (external project)

Expand Down Expand Up @@ -92,8 +93,6 @@ Global options:
- `MPP_BUILD_DOCS` - build documentation
- `MPP_BUILD_BENCHMARKS` - build benchmarks
Library options:
- `MPP_BUILD_SHARED_LIBS` - build shared or static libraries
Expand Down
16 changes: 2 additions & 14 deletions example_project/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "mpplib/containers/gc_graph.hpp"
#include "mpplib/gc.hpp"
#include "mpplib/shared_gcptr.hpp"
#include "mpplib/stl_allocator_interface.hpp"
#include "mpplib/utils/profiler_definitions.hpp"

using namespace mpp;
Expand All @@ -30,20 +31,7 @@ void logic()
using namespace mpp;
using namespace std::literals::chrono_literals;

char* ptr = (char*)MM::Allocate(1024);
SharedGcPtr<char> a(ptr);
SharedGcPtr<UserData> b = MakeSharedGcPtr<UserData>(1337);
SharedGcPtr<UserData> c = MakeSharedGcPtr<UserData>(1337);
SharedGcPtr<UserData> d = MakeSharedGcPtr<UserData>(1337);

a = nullptr;
// b = nullptr;
c = nullptr;
// d = nullptr;

GC::GetInstance().Collect();
// Should trigger invalid initialization
// SharedGcPtr<char> b(ptr);
SharedGcPtr<int32_t> b = MakeSharedGcPtr<int32_t>(1337);
}

int main()
Expand Down
13 changes: 0 additions & 13 deletions libmemplusplus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,6 @@ option(MPP_PROFILE "Build mpp with support of profiling" ON)
option(MPP_COLOUR "Build mpp with support of coloured output" ON)
option(MPP_STATS "Build mpp with support of statistics dumping" ON)

################# BENCHMARKS OPTIONS CHECKING #################
if (MPP_BUILD_BENCHMARKS MATCHES "ON")
if (MPP_FULL_DEBUG MATCHES "ON")
message(WARNING "Building benchmarks in MPP_FULL_DEBUG mode! This may show inaccurate benchmark results.")
endif()
if (MPP_PROFILE MATCHES "ON")
message(WARNING "Building benchmarks with profiling enabled! This may show inaccurate benchmark results.")
endif()
if (MPP_STATS MATCHES "ON")
message(WARNING "Building benchmarks with statistics enabled! This may show inaccurate benchmark results.")
endif()
endif()

################# DEFAULT BUILD TYPE #################
if (NOT CMAKE_BUILD_TYPE)
if ("${CMAKE_BINARY_DIR}" MATCHES ".*(D|d)ebug$")
Expand Down
11 changes: 11 additions & 0 deletions libmemplusplus/include/mpplib/shared_gcptr-imp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ namespace mpp {
return *m_objectPtr;
}

template<class Type>
SharedGcPtr<Type>::operator bool() const
{
return Get() != nullptr;
}

template<class Type>
ptrdiff_t SharedGcPtr<Type>::operator-(const SharedGcPtr<Type>& t_other) const noexcept {
return Get() - t_other.Get();
}

template<class Type>
bool SharedGcPtr<Type>::AddToGcList()
{
Expand Down
10 changes: 10 additions & 0 deletions libmemplusplus/include/mpplib/shared_gcptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ namespace mpp {
*/
Type& operator*() const noexcept;

/**
* @brief Allows automatic conversions to bool.
*/
explicit operator bool() const;

/**
* @brief Calculates distance between two pointers
*/
ptrdiff_t operator-(const SharedGcPtr<Type>& t_other) const noexcept;

/**
* @brief Tries to add SharedGcPtr to list of all active GcPtr's.
* @return true if succeed, false otherwise
Expand Down
99 changes: 0 additions & 99 deletions libmemplusplus/include/mpplib/stl_allocator_interface.hpp

This file was deleted.

3 changes: 3 additions & 0 deletions mempp.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"folders": [
{
"path": "."
},
{
"path": "../memplusplus-benchmarks"
}
],
"settings": {
Expand Down

0 comments on commit 74185a9

Please sign in to comment.