Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
foonathan committed Mar 29, 2015
2 parents 08932ae + 03d8347 commit 1b3cfcc
Show file tree
Hide file tree
Showing 30 changed files with 2,094 additions and 1,120 deletions.
140 changes: 46 additions & 94 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,94 +1,46 @@

# Initializes block variables
INIT_BIICODE_BLOCK()

# Actually create targets: EXEcutables and libraries.
ADD_BIICODE_TARGETS()

INCLUDE(biicode/cmake/tools) # Include tools.cmake file from "cmake" block from the "biicode" user
ACTIVATE_CPP11(INTERFACE ${BII_BLOCK_TARGET})

# You can safely delete lines from here...

###############################################################################
# REFERENCE #
###############################################################################
#
# This CMakeLists.txt file helps defining your block building and compiling
# To learn more about the CMake use with biicode, visit http://docs.biicode.com/c++.html
#
# ----------------------------------------------------
# NEW FEATURE! Include cmake files from remote blocks:
# -----------------------------------------------------
# Now you can handle cmake dependencies alike you do with c/c++:
#
# INCLUDE(user/block/myrecipe) # include myrecipe.cmake from remote user/block
#
# > EXAMPLE: Include our recipes and activate C++11 in your block (http://www.biicode.com/biicode/cmake)
#

#
# Remember to run "bii find" to download out cmake tools file
#
# ---------------------
# INIT_BIICODE_BLOCK()
# ---------------------
# This function creates several helper variables as ${BII_BLOCK_NAME} and ${BII_BLOCK_USER}
# Also it loads variables from the cmake/bii_user_block_vars.cmake
# ${BII_LIB_SRC} File list to create the library
# ${BII_LIB_TYPE} Empty (default, STATIC most casess) STATIC or SHARED
# ${BII_LIB_DEPS} Dependencies to other libraries (user2_block2, user3_blockX)
# ${BII_LIB_SYSTEM_HEADERS} System linking requirements as windows.h, pthread.h, etc
#
# You can use or modify them here, for example, to add or remove files from targets based on OS
# Or use typical cmake configurations done BEFORE defining targets. Examples:
# ADD_DEFINITIONS(-DFOO)
# FIND_PACKAGE(OpenGL QUIET)
# You can add INCLUDE_DIRECTORIES here too
#
# ---------------------
# ADD_BIICODE_TARGETS()
# ---------------------
#
# This function creates the following variables:
# ${BII_BLOCK_TARGET} Interface (no files) target for convenient configuration of all
# targets in this block, as the rest of targets always depend on it
# has name in the form "user_block_interface"
# ${BII_LIB_TARGET} Target library name, usually in the form "user_block". May not exist
# if BII_LIB_SRC is empty
# ${BII_BLOCK_TARGETS} List of all targets defined in this block
# ${BII_BLOCK_EXES} List of executables targets defined in this block
# ${BII_exe_name_TARGET}: Executable target (e.g. ${BII_main_TARGET}. You can also use
# directly the name of the executable target (e.g. user_block_main)
#
# > EXAMPLE: Add include directories to all targets of this block
#
# TARGET_INCLUDE_DIRECTORIES(${BII_BLOCK_TARGET} INTERFACE myincludedir)
#
# You can add private include directories to the Lib (if existing)
#
# > EXAMPLE: Link with pthread:
#
# TARGET_LINK_LIBRARIES(${BII_BLOCK_TARGET} INTERFACE pthread)
# or link against library:
# TARGET_LINK_LIBRARIES(${BII_LIB_TARGET} PUBLIC pthread)
# or directly use the library target name:
# TARGET_LINK_LIBRARIES(user_block PUBLIC pthread)
#
# NOTE: This can be also done adding pthread to ${BII_LIB_DEPS}
# BEFORE calling ADD_BIICODE_TARGETS()
#
# > EXAMPLE: how to activate C++11
#
# IF(APPLE)
# TARGET_COMPILE_OPTIONS(${BII_BLOCK_TARGET} INTERFACE "-std=c++11 -stdlib=libc++")
# ELSEIF (WIN32 OR UNIX)
# TARGET_COMPILE_OPTIONS(${BII_BLOCK_TARGET} INTERFACE "-std=c++11")
# ENDIF(APPLE)
#
# > EXAMPLE: Set properties to target
#
# SET_TARGET_PROPERTIES(${BII_BLOCK_TARGET} PROPERTIES COMPILE_DEFINITIONS "IOV_MAX=255")
#


if (BIICODE)
include(${CMAKE_HOME_DIRECTORY}/biicode.cmake)
include(biicode/cmake/tools)
else()
cmake_minimum_required(VERSION 3.0)
project(foonathan_memory)
endif()

if (BIICODE)
ADD_BIICODE_TARGETS()
set(targets ${BII_BLOCK_TARGETS} CACHE INTERNAL "")

ACTIVATE_CPP11()
else()
set(src
detail/align.hpp
detail/block_list.cpp
detail/block_list.hpp
detail/free_list.cpp
detail/free_list.hpp
detail/memory_stack.hpp
allocator_adapter.hpp
allocator_traits.hpp
heap_allocator.cpp
heap_allocator.hpp
new_allocator.cpp
new_allocator.hpp
pool_allocator.hpp
pool_collection.cpp
pool_collection.hpp
pool_type.hpp
raw_allocator_base.hpp
smart_ptr.hpp
stack_allocator.hpp
std_allocator_base.hpp
tracking.hpp
CACHE INTERNAL "")

add_library(foonathan_memory ${src})
add_executable(foonathan_memory_example ${src} example/main.cpp)

set(targets foonathan_memory foonathan_memory_example CACHE INTERNAL "")

set_target_properties(${targets} PROPERTIES CXX_STANDARD 11)
set_target_properties(${targets} PROPERTIES CXX_STANDARD_REQUIRED ON)
endif()
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (C) 2015 Jonathan Müller <jonathanmueller.dev@gmail.com>

This software is provided 'as-is', without any express or
implied warranty. In no event will the authors be held
liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but
is not required.

2. Altered source versions must be plainly marked as such,
and must not be misrepresented as being the original software.

3. This notice may not be removed or altered from any
source distribution.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
memory
======
This library provides various memory allocators for high-performance allocation and deallocation. These allocators are provided in the form of a new allocator concept: RawAllocator. A RawAllocator is an improved version over the classical STL-Allocator. There are various wrapper classes and traits to convert between the two types. Each RawAllocator has the following interface or an appropriate specialization of the raw_allocator_traits:

// A raw allocator, only supports raw memory allocation.
// Similar to ::operator new/malloc. This avoids the need to be templated and to use one allocator for multiple types.
// The raw_allocator_traits can be specialized to adopt to another interface.
class raw_allocator
{
public:
// Whether or not the allocator is stateful.
// Non-stateful allocators don't need to be stored and can be default constructed on the fly.
using is_stateful = std::true_type/std::false_type;
// The allocator is required to be moveable
raw_allocator(raw_allocator&&);
raw_allocator& operator=(raw_allocator&&);
// Allocates memory for a node. A node is a single object of given size and alignment.
// Precondition: size <= max_node_size() && alignment <= max_alignment()
// Throws an exception derived from std::bad_alloc in case of failure.
void* allocate_node(std::size_t size, std::size_t alignment);
// Allocates memory for an array of multiple nodes.
// Precondition: count * size <= max_array_size() && alignment <= max_alignment()
// Throws an exception derived from std::bad_alloc in case of failure.
void* allocate_array(std::size_t count, std::size_t size, std::size_t alignment);
// Deallocates memory for a node. Must not throw.
void deallocate_node(void *node, std::size_t size, std::size_t alignment) noexcept;
// Deallocates memory for an array of nodes. Must not throw.
void deallocate_array(void *array, std::size_t count, std::size_t size, std::size_t alignment) noexcept;
// Returns the maximum size of a node, inclusive. Should not throw.
std::size_t max_node_size() const;
// Returns the maximum size for an array (total size, no_elements * object_size), inclusive. Should not throw.
std::size_t max_array_size() const;
// Returns the maximum supported alignment, inclusive. Should not throw.
std::size_t max_alignment() const;
};
Loading

0 comments on commit 1b3cfcc

Please sign in to comment.