Skip to content

Commit bcfc60f

Browse files
authored
Merge pull request #48 from ashamis/add_to_readme
Add instructions on how to use the header-only library
2 parents a2dea6c + e326d84 commit bcfc60f

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,27 @@ These can be added to your cmake command line.
8282
-DUSE_MEASURE=ON // Measure performance with histograms
8383
```
8484

85-
The project can be included in other CMake projects as a header
86-
only library:
85+
# Using snmalloc as header-only library
86+
87+
In this section we show how to compile snmalloc into your project such that it replaces the standard allocator functions such as free and malloc. The following instructions were tested with CMake and Clang running on Ubuntu 18.04.
88+
89+
Add these lines to your CMake file.
8790
```
8891
set(SNMALLOC_ONLY_HEADER_LIBRARY ON)
89-
add_subdirectory([...]/snmalloc EXCLUDE_FROM_ALL)
92+
add_subdirectory(snmalloc EXCLUDE_FROM_ALL)
93+
```
94+
95+
In addition make sure your executable is compiled to support 128 bit atomic operations. This may require you to add the following to your CMake file.
96+
```
97+
target_link_libraries([lib_name] PRIVATE snmalloc_lib)
98+
```
99+
100+
You will also need to compile the relavent parts of snmalloc itself. Create a new file with the following contents and compile it with the rest of your application.
101+
```
102+
#define NO_BOOTSTRAP_ALLOCATOR
103+
104+
#include "snmalloc/src/override/malloc.cc"
90105
```
91-
This has a single build target `snmalloc_lib`, which includes
92-
the necessary compiler and linker flags, to use snmalloc as a header-only
93-
library.
94106

95107
# Contributing
96108

0 commit comments

Comments
 (0)