Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
9b040cd7
Commit
9b040cd7
authored
Apr 12, 2018
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added steal_memory() to the matrix.
parent
74a3950c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
138 additions
and
1 deletion
+138
-1
matrix.h
dlib/matrix/matrix.h
+6
-0
matrix_abstract.h
dlib/matrix/matrix_abstract.h
+15
-0
matrix_data_layout.h
dlib/matrix/matrix_data_layout.h
+70
-0
memory_manager_stateless_kernel_1.h
...ory_manager_stateless/memory_manager_stateless_kernel_1.h
+15
-0
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
}
std
::
unique_ptr
<
T
[]
>
steal_memory
(
)
{
return
data
.
steal_memory
();
}
matrix
&
operator
=
(
const
std
::
initializer_list
<
T
>&
l
)
{
matrix
temp
(
l
);
...
...
dlib/matrix/matrix_abstract.h
View file @
9b040cd7
...
...
@@ -480,6 +480,21 @@ namespace dlib
- #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
>
matrix
&
operator
=
(
U
(
&
array
)[
len
]
...
...
dlib/matrix/matrix_data_layout.h
View file @
9b040cd7
...
...
@@ -336,6 +336,14 @@ namespace dlib
nr_
=
nr
;
}
std
::
unique_ptr
<
T
[]
>
steal_memory
()
{
auto
ret
=
pool
.
extract_array
(
data
);
data
=
nullptr
;
nr_
=
0
;
return
ret
;
}
#ifdef MATLAB_MEX_FILE
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."
);
}
...
...
@@ -421,6 +429,14 @@ namespace dlib
nc_
=
nc
;
}
std
::
unique_ptr
<
T
[]
>
steal_memory
()
{
auto
ret
=
pool
.
extract_array
(
data
);
data
=
nullptr
;
nc_
=
0
;
return
ret
;
}
#ifdef MATLAB_MEX_FILE
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."
);
}
...
...
@@ -508,6 +524,15 @@ namespace dlib
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
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."
);
}
...
...
@@ -783,6 +808,14 @@ namespace dlib
nr_
=
nr
;
}
std
::
unique_ptr
<
T
[]
>
steal_memory
()
{
auto
ret
=
pool
.
extract_array
(
data
);
data
=
nullptr
;
nr_
=
0
;
return
ret
;
}
#ifdef MATLAB_MEX_FILE
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."
);
}
...
...
@@ -868,6 +901,14 @@ namespace dlib
nc_
=
nc
;
}
std
::
unique_ptr
<
T
[]
>
steal_memory
()
{
auto
ret
=
pool
.
extract_array
(
data
);
data
=
nullptr
;
nc_
=
0
;
return
ret
;
}
#ifdef MATLAB_MEX_FILE
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."
);
}
...
...
@@ -962,6 +1003,15 @@ namespace dlib
nc_
=
nc
;
}
std
::
unique_ptr
<
T
[]
>
steal_memory
()
{
auto
ret
=
pool
.
extract_array
(
data
);
data
=
nullptr
;
nr_
=
0
;
nc_
=
0
;
return
ret
;
}
private
:
T
*
data
;
long
nr_
;
...
...
@@ -1104,6 +1154,16 @@ namespace dlib
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
:
double
*
data
;
long
nr_
;
...
...
@@ -1247,6 +1307,16 @@ namespace dlib
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
:
float
*
data
;
long
nr_
;
...
...
dlib/memory_manager_stateless/memory_manager_stateless_kernel_1.h
View file @
9b040cd7
...
...
@@ -4,6 +4,7 @@
#define DLIB_MEMORY_MANAGER_STATELESs_1_
#include "memory_manager_stateless_kernel_abstract.h"
#include <memory>
namespace
dlib
{
...
...
@@ -63,6 +64,20 @@ namespace dlib
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
:
// restricted functions
...
...
dlib/memory_manager_stateless/memory_manager_stateless_kernel_abstract.h
View file @
9b040cd7
...
...
@@ -4,6 +4,7 @@
#ifdef DLIB_MEMORY_MANAGER_STATELESs_ABSTRACT_
#include "../algs.h"
#include <memory>
namespace
dlib
{
...
...
@@ -113,10 +114,40 @@ namespace dlib
/*!
ensures
- 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.
!*/
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
:
// 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