Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
9b040cd7
Commit
9b040cd7
authored
Apr 12, 2018
by
Davis King
Browse files
Added steal_memory() to the matrix.
parent
74a3950c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
138 additions
and
1 deletion
+138
-1
dlib/matrix/matrix.h
dlib/matrix/matrix.h
+6
-0
dlib/matrix/matrix_abstract.h
dlib/matrix/matrix_abstract.h
+15
-0
dlib/matrix/matrix_data_layout.h
dlib/matrix/matrix_data_layout.h
+70
-0
dlib/memory_manager_stateless/memory_manager_stateless_kernel_1.h
...ory_manager_stateless/memory_manager_stateless_kernel_1.h
+15
-0
dlib/memory_manager_stateless/memory_manager_stateless_kernel_abstract.h
...ager_stateless/memory_manager_stateless_kernel_abstract.h
+32
-1
No files found.
dlib/matrix/matrix.h
View file @
9b040cd7
...
@@ -1169,6 +1169,12 @@ namespace dlib
...
@@ -1169,6 +1169,12 @@ namespace dlib
}
}
std
::
unique_ptr
<
T
[]
>
steal_memory
(
)
{
return
data
.
steal_memory
();
}
matrix
&
operator
=
(
const
std
::
initializer_list
<
T
>&
l
)
matrix
&
operator
=
(
const
std
::
initializer_list
<
T
>&
l
)
{
{
matrix
temp
(
l
);
matrix
temp
(
l
);
...
...
dlib/matrix/matrix_abstract.h
View file @
9b040cd7
...
@@ -480,6 +480,21 @@ namespace dlib
...
@@ -480,6 +480,21 @@ namespace dlib
- #nc() == 1
- #nc() == 1
!*/
!*/
std
::
unique_ptr
<
T
[]
>
steal_memory
(
);
/*!
requires
- NR*NC==0
(i.e. this array isn't statically sized)
ensures
- Returns a pointer containing the memory block underlying this matrix.
After calling steal_memory() this matrix doesn't own the memory anymore
and is automatically set to the empty matrix.
- The returned pointer points to an array of size() T objects and in
particular is the pointer &(*this)(0,0).
- #size() == 0
!*/
template
<
typename
U
,
size_t
len
>
template
<
typename
U
,
size_t
len
>
matrix
&
operator
=
(
matrix
&
operator
=
(
U
(
&
array
)[
len
]
U
(
&
array
)[
len
]
...
...
dlib/matrix/matrix_data_layout.h
View file @
9b040cd7
...
@@ -336,6 +336,14 @@ namespace dlib
...
@@ -336,6 +336,14 @@ namespace dlib
nr_
=
nr
;
nr_
=
nr
;
}
}
std
::
unique_ptr
<
T
[]
>
steal_memory
()
{
auto
ret
=
pool
.
extract_array
(
data
);
data
=
nullptr
;
nr_
=
0
;
return
ret
;
}
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
...
@@ -421,6 +429,14 @@ namespace dlib
...
@@ -421,6 +429,14 @@ namespace dlib
nc_
=
nc
;
nc_
=
nc
;
}
}
std
::
unique_ptr
<
T
[]
>
steal_memory
()
{
auto
ret
=
pool
.
extract_array
(
data
);
data
=
nullptr
;
nc_
=
0
;
return
ret
;
}
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
...
@@ -508,6 +524,15 @@ namespace dlib
...
@@ -508,6 +524,15 @@ namespace dlib
nc_
=
nc
;
nc_
=
nc
;
}
}
std
::
unique_ptr
<
T
[]
>
steal_memory
()
{
auto
ret
=
pool
.
extract_array
(
data
);
data
=
nullptr
;
nr_
=
0
;
nc_
=
0
;
return
ret
;
}
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
...
@@ -783,6 +808,14 @@ namespace dlib
...
@@ -783,6 +808,14 @@ namespace dlib
nr_
=
nr
;
nr_
=
nr
;
}
}
std
::
unique_ptr
<
T
[]
>
steal_memory
()
{
auto
ret
=
pool
.
extract_array
(
data
);
data
=
nullptr
;
nr_
=
0
;
return
ret
;
}
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
...
@@ -868,6 +901,14 @@ namespace dlib
...
@@ -868,6 +901,14 @@ namespace dlib
nc_
=
nc
;
nc_
=
nc
;
}
}
std
::
unique_ptr
<
T
[]
>
steal_memory
()
{
auto
ret
=
pool
.
extract_array
(
data
);
data
=
nullptr
;
nc_
=
0
;
return
ret
;
}
#ifdef MATLAB_MEX_FILE
#ifdef MATLAB_MEX_FILE
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
void
_private_set_mxArray
(
mxArray
*
)
{
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
mxArray
*
_private_release_mxArray
(){
DLIB_CASSERT
(
false
,
"This function should never be called."
);
}
...
@@ -962,6 +1003,15 @@ namespace dlib
...
@@ -962,6 +1003,15 @@ namespace dlib
nc_
=
nc
;
nc_
=
nc
;
}
}
std
::
unique_ptr
<
T
[]
>
steal_memory
()
{
auto
ret
=
pool
.
extract_array
(
data
);
data
=
nullptr
;
nr_
=
0
;
nc_
=
0
;
return
ret
;
}
private:
private:
T
*
data
;
T
*
data
;
long
nr_
;
long
nr_
;
...
@@ -1104,6 +1154,16 @@ namespace dlib
...
@@ -1104,6 +1154,16 @@ namespace dlib
nc_
=
nc
;
nc_
=
nc
;
}
}
std
::
unique_ptr
<
T
[]
>
steal_memory
()
{
DLIB_CASSERT
(
!
owned_by_matlab
,
"You can't steal the memory from a matrix if it's owned by MATLAB."
);
std
::
unique_ptr
<
T
[]
>
ret
(
data
);
data
=
nullptr
;
nr_
=
0
;
nc_
=
0
;
return
ret
;
}
private:
private:
double
*
data
;
double
*
data
;
long
nr_
;
long
nr_
;
...
@@ -1247,6 +1307,16 @@ namespace dlib
...
@@ -1247,6 +1307,16 @@ namespace dlib
nc_
=
nc
;
nc_
=
nc
;
}
}
std
::
unique_ptr
<
T
[]
>
steal_memory
()
{
DLIB_CASSERT
(
!
owned_by_matlab
,
"You can't steal the memory from a matrix if it's owned by MATLAB."
);
std
::
unique_ptr
<
T
[]
>
ret
(
data
);
data
=
nullptr
;
nr_
=
0
;
nc_
=
0
;
return
ret
;
}
private:
private:
float
*
data
;
float
*
data
;
long
nr_
;
long
nr_
;
...
...
dlib/memory_manager_stateless/memory_manager_stateless_kernel_1.h
View file @
9b040cd7
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#define DLIB_MEMORY_MANAGER_STATELESs_1_
#define DLIB_MEMORY_MANAGER_STATELESs_1_
#include "memory_manager_stateless_kernel_abstract.h"
#include "memory_manager_stateless_kernel_abstract.h"
#include <memory>
namespace
dlib
namespace
dlib
{
{
...
@@ -63,6 +64,20 @@ namespace dlib
...
@@ -63,6 +64,20 @@ namespace dlib
void
swap
(
memory_manager_stateless_kernel_1
&
)
void
swap
(
memory_manager_stateless_kernel_1
&
)
{}
{}
std
::
unique_ptr
<
T
>
extract
(
T
*
item
)
{
return
std
::
unique_ptr
<
T
>
(
item
);
}
std
::
unique_ptr
<
T
[]
>
extract_array
(
T
*
item
)
{
return
std
::
unique_ptr
<
T
[]
>
(
item
);
}
private:
private:
// restricted functions
// restricted functions
...
...
dlib/memory_manager_stateless/memory_manager_stateless_kernel_abstract.h
View file @
9b040cd7
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#ifdef DLIB_MEMORY_MANAGER_STATELESs_ABSTRACT_
#ifdef DLIB_MEMORY_MANAGER_STATELESs_ABSTRACT_
#include "../algs.h"
#include "../algs.h"
#include <memory>
namespace
dlib
namespace
dlib
{
{
...
@@ -113,10 +114,40 @@ namespace dlib
...
@@ -113,10 +114,40 @@ namespace dlib
/*!
/*!
ensures
ensures
- this function has no effect on *this or item. It is just provided
- this function has no effect on *this or item. It is just provided
to make this object's interface more compat
a
ble with the other
to make this object's interface more compat
i
ble with the other
memory managers.
memory managers.
!*/
!*/
std
::
unique_ptr
<
T
>
extract
(
T
*
item
);
/*!
requires
- item == is a pointer to memory that was obtained from a call to
allocate().
ensures
- returns a unique_ptr that owns item. That is, if the returned ptr is
PTR then PTR.get() == item. Therefore, this function extracts item
from the memory manager's internal pool. Therefore, you shouldn't
call deallocate(item) after this.
- Note that not all memory managers implement extract().
!*/
std
::
unique_ptr
<
T
[]
>
extract_array
(
T
*
item
);
/*!
requires
- item == is a pointer to memory that was obtained from a call to
allocate_array().
ensures
- returns a unique_ptr that owns item. That is, if the returned ptr is
PTR then PTR.get() == item. Therefore, this function extracts item
from the memory manager's internal pool. Therefore, you shouldn't
call deallocate_array(item) after this.
- Note that not all memory managers implement extract().
!*/
private:
private:
// restricted functions
// restricted functions
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment