Skip to content

Commit 71d5341

Browse files
cas4eySergey Yagovtsev
authored andcommitted
Linux build
1 parent 0496936 commit 71d5341

File tree

4 files changed

+110
-110
lines changed

4 files changed

+110
-110
lines changed

‎include/shared_allocator/cached_allocator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ namespace salloc {
273273
template <class U>
274274
inline void construct(U* _singleObject, U&& _value)
275275
{
276-
m_allocator.construct(_singleObject, _value);
276+
m_allocator.construct(_singleObject, ::std::forward<U&&>(_value));
277277
}
278278

279279
/** \brief Construct new object on preallocated memory using arguments list.

‎include/shared_allocator/shared_allocator.hpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
#ifndef SHARED___ALLOCATOR_____HPP___
4141
#define SHARED___ALLOCATOR_____HPP___
4242

43-
#include <xstddef>
43+
#include <memory>
44+
#include <stddef.h>
4445
#include <type_traits>
4546

4647
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -98,7 +99,7 @@ namespace salloc {
9899

99100
template <class T>
100101
inline void shared_construct(T* _instance, T&& _value) {
101-
::new (static_cast<void*>(_instance)) T(_value);
102+
::new (static_cast<void*>(_instance)) T(::std::forward<T&&>(_value));
102103
}
103104

104105
template <class T>
@@ -115,19 +116,19 @@ namespace salloc {
115116
inline void shared_construct(TYPENAME* _instance) { *_instance = DEFAULT_VALUE; } \
116117
inline void shared_construct(TYPENAME* _instance, TYPENAME _value) { *_instance = _value; }
117118

118-
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(bool, false);
119-
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(char, 0);
120-
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(unsigned char, 0);
121-
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(short, 0);
122-
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(unsigned short, 0);
123-
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(int, 0);
124-
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(unsigned int, 0);
125-
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(long, 0);
126-
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(unsigned long, 0);
127-
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(long long, 0LL);
128-
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(unsigned long long, 0ULL);
129-
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(float, 0.f);
130-
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(double, 0.0);
119+
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(bool, false)
120+
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(char, 0)
121+
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(unsigned char, 0)
122+
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(short, 0)
123+
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(unsigned short, 0)
124+
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(int, 0)
125+
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(unsigned int, 0)
126+
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(long, 0)
127+
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(unsigned long, 0)
128+
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(long long, 0LL)
129+
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(unsigned long long, 0ULL)
130+
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(float, 0.f)
131+
SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR(double, 0.0)
131132

132133
#undef SHARED_ALLOCATOR_DECLARE_DEFAULT_CONSTRUCTOR
133134

@@ -285,7 +286,7 @@ namespace salloc {
285286
template <class U>
286287
void construct(U* _singleObject, U&& _value) const
287288
{
288-
shared_construct(_singleObject, _value);
289+
shared_construct(_singleObject, ::std::forward<U&&>(_value));
289290
}
290291

291292
/** \brief Construct new object on preallocated memory using arguments list.

‎source/shared_allocator.cpp

Lines changed: 91 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,63 @@
1-
/***************************************************************************************
2-
* file : shared_allocator.cpp
3-
* data : 2016/03/05
4-
* author : Victor Zarubkin
5-
* contact : v.s.zarubkin@gmail.com
6-
* copyright : Copyright (C) 2016 Victor Zarubkin
7-
* :
8-
* description : This header contains implementation of shared_allocate,
9-
* : shared_deallocate and shared_size functions.
10-
* :
11-
* references : Original (and actual) version of source code can be found
12-
* : here <http://www.github.com/cas4ey/shared_allocator>.
13-
* :
14-
* license : This file is part of SharedAllocator.
15-
* :
16-
* : The MIT License (MIT)
17-
* : Permission is hereby granted, free of charge, to any person
18-
* : obtaining a copy of this software and associated documentation
19-
* : files (the "Software"), to deal in the Software without
20-
* : restriction, including without limitation the rights to use,
21-
* : copy, modify, merge, publish, distribute, sublicense, and/or sell
22-
* : copies of the Software, and to permit persons to whom the Software
23-
* : is furnished to do so, subject to the following conditions:
24-
* :
25-
* : The above copyright notice and this permission notice shall be
26-
* : included in all copies or substantial portions of the Software.
27-
* :
28-
* : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29-
* : EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30-
* : OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
31-
* : IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
32-
* : ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
33-
* : TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
34-
* : OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35-
****************************************************************************************/
36-
37-
#include <xstddef>
38-
#include <type_traits>
39-
#include <malloc.h>
40-
41-
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
42-
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
43-
44-
#if defined(WIN32) || defined(_WIN32) || defined(_WIN64)
45-
46-
# define SHARED_ALLOCATOR_DLLEXPORT __declspec(dllexport)
47-
48-
#else
49-
50-
# define SHARED_ALLOCATOR_DLLEXPORT
51-
52-
#endif // defined(WIN32) || defined(_WIN32) || defined(_WIN64)
53-
54-
extern "C"
55-
{
56-
/** \brief Allocate new memory.
57-
58-
\param _bytesNumber Required bytes number including already preallocated size of _currentMemory (if exist).
59-
\param _currentMemory Pointer to existing memory buffer (if exist). If it's size is greater than _bytesNumber then no new memory would be allocated. */
60-
SHARED_ALLOCATOR_DLLEXPORT void* shared_allocate(size_t _bytesNumber, void* _currentMemory = nullptr)
61-
{
1+
/***************************************************************************************
2+
* file : shared_allocator.cpp
3+
* data : 2016/03/05
4+
* author : Victor Zarubkin
5+
* contact : v.s.zarubkin@gmail.com
6+
* copyright : Copyright (C) 2016 Victor Zarubkin
7+
* :
8+
* description : This header contains implementation of shared_allocate,
9+
* : shared_deallocate and shared_size functions.
10+
* :
11+
* references : Original (and actual) version of source code can be found
12+
* : here <http://www.github.com/cas4ey/shared_allocator>.
13+
* :
14+
* license : This file is part of SharedAllocator.
15+
* :
16+
* : The MIT License (MIT)
17+
* : Permission is hereby granted, free of charge, to any person
18+
* : obtaining a copy of this software and associated documentation
19+
* : files (the "Software"), to deal in the Software without
20+
* : restriction, including without limitation the rights to use,
21+
* : copy, modify, merge, publish, distribute, sublicense, and/or sell
22+
* : copies of the Software, and to permit persons to whom the Software
23+
* : is furnished to do so, subject to the following conditions:
24+
* :
25+
* : The above copyright notice and this permission notice shall be
26+
* : included in all copies or substantial portions of the Software.
27+
* :
28+
* : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29+
* : EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30+
* : OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
31+
* : IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
32+
* : ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
33+
* : TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
34+
* : OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35+
****************************************************************************************/
36+
37+
#include <type_traits>
38+
#include <malloc.h>
39+
40+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
41+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
42+
43+
#if defined(WIN32) || defined(_WIN32) || defined(_WIN64)
44+
45+
# define SHARED_ALLOCATOR_DLLEXPORT __declspec(dllexport)
46+
47+
#else
48+
49+
# define SHARED_ALLOCATOR_DLLEXPORT
50+
51+
#endif // defined(WIN32) || defined(_WIN32) || defined(_WIN64)
52+
53+
extern "C"
54+
{
55+
/** \brief Allocate new memory.
56+
57+
\param _bytesNumber Required bytes number including already preallocated size of _currentMemory (if exist).
58+
\param _currentMemory Pointer to existing memory buffer (if exist). If it's size is greater than _bytesNumber then no new memory would be allocated. */
59+
SHARED_ALLOCATOR_DLLEXPORT void* shared_allocate(size_t _bytesNumber, void* _currentMemory = nullptr)
60+
{
6261
if (_currentMemory == nullptr)
6362
{
6463
size_t* newMemory = reinterpret_cast<size_t*>(malloc(_bytesNumber + sizeof(size_t)));
@@ -74,39 +73,39 @@ extern "C"
7473

7574
size_t* newMemory = reinterpret_cast<size_t*>(realloc(pMemory, _bytesNumber + sizeof(size_t)));
7675
*newMemory = _bytesNumber;
77-
return static_cast<void*>(newMemory + 1);
78-
}
79-
80-
/** \brief Deallocate memory.
81-
82-
\param _currentMemory Pointer to existing memory buffer to be deallocated.
83-
84-
\warning Pointer to _currentMemory after this operation will be invalid. */
85-
SHARED_ALLOCATOR_DLLEXPORT void shared_deallocate(void* _currentMemory)
86-
{
76+
return static_cast<void*>(newMemory + 1);
77+
}
78+
79+
/** \brief Deallocate memory.
80+
81+
\param _currentMemory Pointer to existing memory buffer to be deallocated.
82+
83+
\warning Pointer to _currentMemory after this operation will be invalid. */
84+
SHARED_ALLOCATOR_DLLEXPORT void shared_deallocate(void* _currentMemory)
85+
{
8786
if (_currentMemory != nullptr)
8887
{
8988
size_t* pMemory = reinterpret_cast<size_t*>(_currentMemory) - 1;
90-
free(pMemory);
91-
}
92-
}
93-
94-
/** \brief Returns memory size in bytes.
95-
96-
\param _currentMemory Pointer to existing memory buffer. */
97-
SHARED_ALLOCATOR_DLLEXPORT size_t shared_size(const void* _currentMemory)
98-
{
89+
free(pMemory);
90+
}
91+
}
92+
93+
/** \brief Returns memory size in bytes.
94+
95+
\param _currentMemory Pointer to existing memory buffer. */
96+
SHARED_ALLOCATOR_DLLEXPORT size_t shared_size(const void* _currentMemory)
97+
{
9998
if (_currentMemory != nullptr)
10099
{
101-
return *(reinterpret_cast<const size_t*>(_currentMemory) - 1);
102-
}
103-
104-
return 0;
105-
}
106-
107-
}
108-
109-
#undef SHARED_ALLOCATOR_DLLEXPORT
110-
111-
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
112-
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
100+
return *(reinterpret_cast<const size_t*>(_currentMemory) - 1);
101+
}
102+
103+
return 0;
104+
}
105+
106+
}
107+
108+
#undef SHARED_ALLOCATOR_DLLEXPORT
109+
110+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
111+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

‎test/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "shared_allocator/shared_allocator.hpp"
99
#include "shared_allocator/cached_allocator.hpp"
1010
#include "shared_allocator/size_cached_allocator.hpp"
11-
11+
#include <string.h>
1212
//////////////////////////////////////////////////////////////////////////
1313
//////////////////////////////////////////////////////////////////////////
1414

0 commit comments

Comments
 (0)