Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90694795
aka_static_memory.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Nov 3, 22:46
Size
5 KB
Mime Type
text/x-c++
Expires
Tue, Nov 5, 22:46 (2 d)
Engine
blob
Format
Raw Data
Handle
22096827
Attached To
rAKA akantu
aka_static_memory.hh
View Options
/**
* @file aka_static_memory.hh
*
* @author Nicolas Richart <nicolas.richart@epfl.ch>
*
* @date creation: Fri Jun 18 2010
* @date last modification: Sun Oct 19 2014
*
* @brief Memory management
*
* @section LICENSE
*
* Copyright (©) 2010-2012, 2014, 2015 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Akantu is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Akantu is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Akantu. If not, see <http://www.gnu.org/licenses/>.
*
* @section DESCRIPTION
*
* The class handling the memory, allocation/reallocation/desallocation
* The objects can register their array and ask for allocation or realocation
*
*/
/* -------------------------------------------------------------------------- */
#ifndef __AKANTU_STATIC_MEMORY_HH__
#define __AKANTU_STATIC_MEMORY_HH__
/* -------------------------------------------------------------------------- */
#include "aka_common.hh"
#include "aka_array.hh"
/* -------------------------------------------------------------------------- */
#include <map>
/* -------------------------------------------------------------------------- */
__BEGIN_AKANTU__
typedef
std
::
map
<
ID
,
ArrayBase
*>
ArrayMap
;
typedef
std
::
map
<
MemoryID
,
ArrayMap
>
MemoryMap
;
/**
* @class StaticMemory
* @brief Class for memory management common to all objects (this class as to
* be accessed by an interface class memory)
*/
class
StaticMemory
{
/* ------------------------------------------------------------------------ */
/* Constructors/Destructors */
/* ------------------------------------------------------------------------ */
private
:
/// Default constructor
StaticMemory
(){};
public
:
virtual
~
StaticMemory
();
/* ------------------------------------------------------------------------ */
/* Accessors */
/* ------------------------------------------------------------------------ */
public
:
/// Get the global instance of the StaticMemory
static
StaticMemory
&
getStaticMemory
();
static
bool
isInstantiated
()
{
return
is_instantiated
;
};
/// remove a reference on the static memory
void
destroy
();
/// access to an Array
inline
const
ArrayBase
&
getArray
(
const
MemoryID
&
memory_id
,
const
ID
&
name
)
const
;
/// get all vectors of a memory
inline
const
ArrayMap
&
getMemory
(
const
MemoryID
&
memory_id
)
const
;
/* ------------------------------------------------------------------------ */
/* Class Methods */
/* ------------------------------------------------------------------------ */
public
:
/**
* Allocation of an array of type
*
* @param memory_id the id of the memory accessing to the static memory
* @param name name of the array (for example connectivity)
* @param size number of size (for example number of nodes)
* @param nb_component number of component (for example spatial dimension)
* @param type the type code of the array to be allocated
*
* @return pointer to an array of size nb_tupes * nb_component * sizeof(T)
*/
template
<
typename
T
>
Array
<
T
>
&
smalloc
(
const
MemoryID
&
memory_id
,
const
ID
&
name
,
UInt
size
,
UInt
nb_component
);
template
<
typename
T
>
Array
<
T
>
&
smalloc
(
const
MemoryID
&
memory_id
,
const
ID
&
name
,
UInt
size
,
UInt
nb_component
,
const
T
&
init_value
);
/**
* free the memory associated to the array name
*
* @param memory_id the id of the memory accessing to the static memory
* @param name the name of an existing array
*/
void
sfree
(
const
MemoryID
&
memory_id
,
const
ID
&
name
);
/// function to print the containt of the class
virtual
void
printself
(
std
::
ostream
&
stream
,
int
indent
=
0
)
const
;
/* ------------------------------------------------------------------------ */
/* Class Members */
/* ------------------------------------------------------------------------ */
private
:
/// is the static memory instantiated
static
bool
is_instantiated
;
/// unique instance of the StaticMemory
static
StaticMemory
*
single_static_memory
;
/// map of all allocated arrays, indexed by their names
MemoryMap
memories
;
/// number of references on the static memory
static
UInt
nb_reference
;
};
#include "aka_static_memory_tmpl.hh"
#include "aka_static_memory_inline_impl.cc"
/* -------------------------------------------------------------------------- */
/* inline functions */
/* -------------------------------------------------------------------------- */
/// standard output stream operator
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
stream
,
const
StaticMemory
&
_this
)
{
_this
.
printself
(
stream
);
return
stream
;
}
__END_AKANTU__
#endif
/* __AKANTU_STATIC_MEMORY_HH__ */
Event Timeline
Log In to Comment