17 #include "atlas/library/config.h" 18 #include "atlas/util/Allocate.h" 20 #include "atlas/runtime/Exception.h" 32 SVector() : data_(
nullptr ), size_( 0 ), externally_allocated_(
false ) {}
35 SVector(
const T* data,
const idx_t size ) : data_( data ), size_( size ), externally_allocated_(
true ) {}
40 SVector( SVector
const& other ) : data_( other.data_ ), size_( other.size_ ), externally_allocated_(
true ) {}
44 SVector( SVector&& other ) :
45 data_( other.data_ ), size_( other.size_ ), externally_allocated_( other.externally_allocated_ ) {
46 other.data_ =
nullptr;
48 other.externally_allocated_ =
true;
52 SVector& operator=( SVector&& other ) {
55 externally_allocated_ = other.externally_allocated_;
56 other.data_ =
nullptr;
58 other.externally_allocated_ =
true;
63 SVector( T* data,
idx_t size ) : data_( data ), size_( size ), externally_allocated_(
true ) {}
65 SVector(
idx_t N ) : data_(
nullptr ), size_( N ), externally_allocated_(
false ) { allocate( data_, N ); }
68 ~SVector() { clear(); }
72 if ( data_ && !externally_allocated_ ) {
74 deallocate( data_, size_ );
79 externally_allocated_ =
false;
84 allocate( data, size_ + dimsize );
85 for (
idx_t c = 0; c < pos; ++c ) {
86 data[c] = std::move( data_[c] );
88 for (
idx_t c = pos; c < size_; ++c ) {
89 data[c + dimsize] = std::move( data_[c] );
91 deallocate( data_, size_ );
96 size_t footprint()
const {
return sizeof( T ) * size_; }
99 T* data() {
return data_; }
102 T
const* data()
const {
return data_; }
105 T& operator()(
const idx_t idx ) {
106 assert( data_ && idx < size_ );
110 T
const& operator()(
const idx_t idx )
const {
111 assert( data_ && idx < size_ );
116 T& operator[](
const idx_t idx ) {
117 assert( data_ && idx < size_ );
121 T
const& operator[](
const idx_t idx )
const {
122 assert( data_ && idx < size_ );
127 idx_t size()
const {
return size_; }
129 void resize_impl(
idx_t N ) {
135 for (
idx_t c = 0; c < std::min( size_, N ); ++c ) {
136 d_[c] = std::move( data_[c] );
138 deallocate( data_, size_ );
142 void resize(
idx_t N ) {
143 #ifndef __CUDA_ARCH__ 144 ATLAS_ASSERT( not externally_allocated_,
"Cannot resize externally allocated (or wrapped) data" );
151 static void allocate( T*& ptr,
idx_t size ) {
153 util::allocate_managedmem( ptr, size );
154 for (
idx_t c = 0; c < size; ++c ) {
159 static void deallocate( T*& ptr,
idx_t size ) {
161 for (
idx_t c = 0; c < size; ++c ) {
164 util::delete_managedmem( ptr );
171 bool externally_allocated_;
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
long idx_t
Integer type for indices in connectivity tables.
Definition: config.h:42