7 static void raw_free(
void * p_block)
throw() {free(p_block);}
10 if (p_size == 0) {
raw_free(p_ptr);
return NULL;}
11 else if (p_ptr == NULL)
return raw_malloc(p_size);
16 if (p_block == NULL)
return p_size == 0;
18 if (p_size == 0)
return false;
19 return _expand(p_block,p_size) != NULL;
27 return pfc::mul_safe_t<std::bad_alloc,t_size>(p_width,
sizeof(
T));
32 return reinterpret_cast<T*
>(
raw_malloc(calc_array_width<T>(p_size)));
37 raw_free(reinterpret_cast<void*>(p_block));
42 return reinterpret_cast<T*
>(
raw_realloc(p_block,calc_array_width<T>(p_size)));
51 template<
typename t_exception,
typename t_
int>
53 t_int newval = p_val << p_shift;
54 if (newval >> p_shift != p_val)
throw t_exception();
64 const t_item &
operator[](
t_size p_index)
const {
throw pfc::exception_not_implemented();}
73 const t_item *
get_ptr()
const {
throw pfc::exception_not_implemented();}
74 t_item *
get_ptr() {
throw pfc::exception_not_implemented();}
77 void move_from(t_self &) {
throw pfc::exception_not_implemented();}
79 const t_self &
operator=(
const t_self &) {
throw pfc::exception_not_implemented();}
80 alloc_dummy(
const t_self&) {
throw pfc::exception_not_implemented();}
83 template<
typename t_item>
85 return p_pointer >=
reinterpret_cast<const void*
>(p_buffer) && p_pointer < reinterpret_cast<const void*>(p_buffer + p_buffer_size);
95 if (p_size != m_size) {
96 t_item * l_data = NULL;
97 if (p_size > 0) l_data =
new t_item[p_size];
110 const t_item &
operator[](
t_size p_index)
const {PFC_ASSERT(p_index < m_size);
return m_data[p_index];}
111 t_item &
operator[](
t_size p_index) {PFC_ASSERT(p_index < m_size);
return m_data[p_index];}
117 const t_item *
get_ptr()
const {
return m_data;}
130 const t_self &
operator=(
const t_self &) {
throw pfc::exception_not_implemented();}
145 PFC_ASSERT(p_size <= p_size_total);
146 PFC_ASSERT(m_size <= m_size_total);
147 if (p_size_total > m_size_total) {
148 resize_storage(p_size_total);
149 resize_content(p_size);
151 resize_content(p_size);
152 resize_storage(p_size_total);
160 const t_item &
operator[](
t_size p_index)
const {PFC_ASSERT(p_index < m_size);
return m_buffer[p_index];}
161 t_item &
operator[](
t_size p_index) {PFC_ASSERT(p_index < m_size);
return m_buffer[p_index];}
166 const t_item *
get_ptr()
const {
return m_buffer;}
176 const t_self &
operator=(
const t_self &) {
throw pfc::exception_not_implemented();}
182 if (p_size > m_size) {
186 }
while(m_size < p_size);
187 }
else if (p_size < m_size) {
197 PFC_ASSERT( m_size <= m_size_total );
198 PFC_ASSERT( m_size <= p_size );
199 if (m_size_total != p_size) {
202 m_size_total = p_size;
205 m_size_total = p_size;
207 t_item * newbuffer = pfc::__raw_malloc_t<t_item>(p_size);
216 m_buffer = newbuffer;
217 m_size_total = p_size;
234 if (p_size > m_size) {
235 resize_storage(p_size);
236 resize_content(p_size);
237 }
else if (p_size < m_size) {
238 resize_content(p_size);
239 resize_storage(p_size);
246 const t_item &
operator[](
t_size p_index)
const {PFC_ASSERT(p_index < m_size);
return m_buffer[p_index];}
247 t_item &
operator[](
t_size p_index) {PFC_ASSERT(p_index < m_size);
return m_buffer[p_index];}
252 const t_item *
get_ptr()
const {
return m_buffer;}
261 const t_self &
operator=(
const t_self &) {
throw pfc::exception_not_implemented();}
267 if (p_size > m_size) {
271 }
while(m_size < p_size);
272 }
else if (p_size < m_size) {
282 PFC_ASSERT( m_size <= p_size );
290 t_item * newbuffer = pfc::__raw_malloc_t<t_item>(p_size);
299 m_buffer = newbuffer;
319 const t_item *
get_ptr()
const {
return m_content.get_ptr();}
320 t_item *
get_ptr() {
return m_content.get_ptr();}
322 bool is_ptr_owned(
const void * p_item)
const {
return m_content.is_ptr_owned(p_item);}
328 void move_from(t_self & other) { m_content.move_from(other.m_content); }
331 const t_self &
operator=(
const t_self&) {
throw pfc::exception_not_implemented();}
342 t_size size_base = m_data.get_size_total();
343 if (size_base == 0) size_base = 1;
344 while(size_base < p_size) {
345 size_base = safe_shift_left_t<std::bad_alloc,t_size>(size_base,1);
347 while(size_base >> 2 > p_size) {
350 m_data.set_size(p_size,size_base);
357 const t_item *
get_ptr()
const {
return m_data.get_ptr();}
359 bool is_ptr_owned(
const void * p_item)
const {
return m_data.is_ptr_owned(p_item);}
365 void move_from(t_self & other) { m_data.move_from(other.m_data); }
367 alloc_fast(
const t_self &) {
throw pfc::exception_not_implemented();}
368 const t_self &
operator=(
const t_self&) {
throw pfc::exception_not_implemented();}
378 t_size size_base = m_data.get_size_total();
379 if (size_base == 0) size_base = 1;
380 while(size_base < p_size) {
381 size_base = safe_shift_left_t<std::bad_alloc,t_size>(size_base,1);
383 m_data.set_size(p_size,size_base);
388 t_size size_base = m_data.get_size_total();
389 if (size_base == 0) size_base = 1;
390 while(size_base < p_size) {
391 size_base = safe_shift_left_t<std::bad_alloc,t_size>(size_base,1);
393 m_data.set_size(m_data.get_size(),size_base);
401 const t_item *
get_ptr()
const {
return m_data.get_ptr();}
403 bool is_ptr_owned(
const void * p_item)
const {
return m_data.is_ptr_owned(p_item);}
408 void move_from(t_self & other) { m_data.move_from(other.m_data); }
411 const t_self &
operator=(
const t_self&) {
throw pfc::exception_not_implemented();}
417 template<
typename t_item>
class alloc {
425 if (p_size > p_width)
throw pfc::exception_overflow();
426 else if (p_size > m_size) {
429 }
else if (p_size < m_size) {
441 t_item *
get_ptr() {
return reinterpret_cast<t_item*
>(&m_array);}
442 const t_item *
get_ptr()
const {
return reinterpret_cast<const t_item*
>(&m_array);}
453 const size_t count = other.
get_size();
455 for(
size_t w = 0; w < count; ++w) this->
get_ptr()[w] = other.
get_ptr()[w];
458 alloc(
const t_self&) {
throw pfc::exception_not_implemented();}
459 const t_self&
operator=(
const t_self&) {
throw pfc::exception_not_implemented();}
468 template<
typename t_item>
class alloc {
474 if (p_size > p_width) {
475 m_fixed.set_size(p_width);
476 m_variable.set_size(p_size - p_width);
478 m_fixed.set_size(p_size);
479 m_variable.set_size(0);
485 if (p_index < p_width)
return m_fixed[p_index];
486 else return m_variable[p_index - p_width];
491 if (p_index < p_width)
return m_fixed[p_index];
492 else return m_variable[p_index - p_width];
496 bool is_ptr_owned(
const void * p_item)
const {
return m_fixed.is_ptr_owned(p_item) || m_variable.is_ptr_owned(p_item);}
498 if (p_size > p_width) m_variable.prealloc(p_size - p_width);
501 m_fixed.force_reset(); m_variable.force_reset();
506 m_fixed.move_from(other.
m_fixed);
510 alloc(
const t_self&) {
throw pfc::exception_not_implemented();}
511 const t_self&
operator=(
const t_self&) {
throw pfc::exception_not_implemented();}
524 #if 0//not working (compiler bug?) 528 needs_constructor =
true,
532 template<t_size p_w
idth,
template<
typename>
class t_alloc,
typename t_item>
const t_item * get_ptr() const
void set_size(t_size p_size)
const t_item * get_ptr() const
bool is_ptr_owned(const void *p_item) const
alloc_fast_aggressive< t_item > t_self
void set_size(t_size p_size, t_size p_size_total)
void resize_content(t_size p_size)
static void raw_free(void *p_block)
alloc_simple(const t_self &)
void prealloc(t_size p_size)
bool is_ptr_owned(const void *p_item) const
void set_size(t_size p_size)
void __unsafe__in_place_destructor_array_t(t_type *p_items, t_size p_count)
T min_t(const T &item1, const T &item2)
__array_fast_helper_t< t_item > m_data
alloc_fast(const t_self &)
const t_item * get_ptr() const
t_type replace_null_t(t_type &p_var)
t_size get_size_total() const
void move_from(t_self &other)
void set_size(t_size p_size)
T * __raw_malloc_t(t_size p_size)
const t_item & operator[](t_size p_index) const
void set_size(t_size p_size)
const t_self & operator=(const t_self &)
const t_item & operator[](t_size p_index) const
alloc_fast< t_item > t_self
void resize_content(t_size p_size)
__array_lite_helper_t< t_item > m_content
const t_item & operator[](t_size p_index) const
void move_from(t_self &other)
const t_item * get_ptr() const
t_item & operator[](t_size p_index)
void move_from(t_self &other)
t_item & operator[](t_size n)
bool is_ptr_owned(const void *p_item) const
t_item & operator[](t_size p_index)
t_int safe_shift_left_t(t_int p_val, t_size p_shift=1)
void move_from(t_self &other)
t_type * __unsafe__in_place_constructor_array_copy_t(t_type *p_items, t_size p_count, const t_copy *p_copyfrom)
void __raw_free_t(T *p_block)
bool is_ptr_owned(const void *p_item) const
t_alloc< t_item > m_variable
const t_item & operator[](t_size p_index) const
void move_from(t_self &other)
const t_item * get_ptr() const
const t_item & operator[](t_size n) const
void move_from(t_self &other)
t_size calc_array_width(t_size p_width)
alloc_dummy(const t_self &)
void set_size(t_size p_size)
t_item & operator[](t_size p_index)
bool is_ptr_owned(const void *p_item) const
const t_item & operator[](t_size p_index) const
alloc_dummy< t_item > t_self
__array_fast_helper_t< t_item > t_self
void move_from(t_self &other)
t_item & operator[](t_size p_index)
const t_self & operator=(const t_self &)
const t_item * get_ptr() const
static void * raw_malloc(t_size p_size)
T * new_ptr_check_t(T *p_ptr)
const t_item * get_ptr() const
static bool raw_realloc_inplace(void *p_block, t_size p_size)
bool __raw_realloc_inplace_t(T *p_block, t_size p_size)
alloc_standard< t_item > t_self
const t_self & operator=(const t_self &)
alloc_fast_aggressive(const t_self &)
T * __raw_realloc_t(T *p_block, t_size p_size)
const t_self & operator=(const t_self &)
bool is_ptr_owned(const void *p_item) const
const t_item & operator[](t_size p_index) const
const t_self & operator=(const t_self &)
void prealloc(t_size p_size)
alloc_standard(const t_self &)
t_item & operator[](t_size p_index)
bool is_ptr_owned(const void *p_item) const
t_item & operator[](t_size p_index)
const t_self & operator=(const t_self &)
const t_self & operator=(const t_self &)
void __unsafe__in_place_constructor_t(t_type &p_item)
void resize_storage(t_size p_size)
const t_item & operator[](t_size p_index) const
t_type * __unsafe__in_place_constructor_array_t(t_type *p_items, t_size p_count)
alloc_fixed< p_width >::template alloc< t_item > m_fixed
Simple inefficient fully portable allocator.
void set_size(t_size p_size)
void set_size(t_size p_size)
__array_lite_helper_t< t_item > t_self
void memcpy_t(t_dst *p_dst, const t_src *p_src, t_size p_count)
void move_from(t_self &other)
const t_item * get_ptr() const
__array_fast_helper_t< t_item > m_data
alloc_simple< t_item > t_self
static void * raw_realloc(void *p_ptr, t_size p_size)
const t_item & operator[](t_size p_index) const
void set_size(t_size p_size)
t_item & operator[](t_size p_index)
bool is_ptr_owned(const void *p_item) const
bool is_ptr_owned(const void *p_item) const
t_item & operator[](t_size p_index)
__array_fast_helper_t(const t_self &)
const t_self & operator=(const t_self &)
void prealloc(t_size p_size)
bool is_pointer_in_range(const t_item *p_buffer, t_size p_buffer_size, const void *p_pointer)
const t_self & operator=(const t_self &)
__array_lite_helper_t(const t_self &)
void resize_storage(t_size p_size)