aboutsummaryrefslogtreecommitdiff
path: root/core/dvector.h
diff options
context:
space:
mode:
authorJuan Linietsky2017-01-08 02:04:53 -0300
committerJuan Linietsky2017-01-08 02:04:53 -0300
commit8b912d11152410302f45eaa117c19b7016d781f5 (patch)
tree58e7e9ab9ee7e22c5f7e70c4342219a5918fd55e /core/dvector.h
parent2ab83e1abbf5ee6d00e16056a9e9394114026f28 (diff)
downloadgodot-8b912d11152410302f45eaa117c19b7016d781f5.tar.gz
godot-8b912d11152410302f45eaa117c19b7016d781f5.tar.zst
godot-8b912d11152410302f45eaa117c19b7016d781f5.zip
Diffstat (limited to 'core/dvector.h')
-rw-r--r--core/dvector.h38
1 files changed, 33 insertions, 5 deletions
diff --git a/core/dvector.h b/core/dvector.h
index f109f842a..cac9e8ef8 100644
--- a/core/dvector.h
+++ b/core/dvector.h
@@ -127,15 +127,30 @@ class PoolVector {
MemoryPool::alloc_mutex->unlock();
+
if (MemoryPool::memory_pool) {
} else {
alloc->mem = memalloc( alloc->size );
- copymem( alloc->mem, old_alloc->mem, alloc->size );
}
- if (old_alloc->refcount.unref()) {
+ {
+ Write w;
+ w._ref(alloc);
+ Read r;
+ r._ref(old_alloc);
+
+ int cur_elements = alloc->size/sizeof(T);
+ T*dst = (T*)w.ptr();
+ const T*src = (const T*)r.ptr();
+ for(int i=0;i<cur_elements;i++) {
+ memnew_placement(&dst[i],T(src[i]));
+ }
+ }
+
+
+ if (old_alloc->refcount.unref()==true) {
//this should never happen but..
#ifdef DEBUG_ENABLED
@@ -144,6 +159,17 @@ class PoolVector {
MemoryPool::alloc_mutex->unlock();
#endif
+ {
+ Write w;
+ w._ref(old_alloc);
+
+ int cur_elements = old_alloc->size/sizeof(T);
+ T*elems = (T*)w.ptr();
+ for(int i=0;i<cur_elements;i++) {
+ elems[i].~T();
+ }
+
+ }
if (MemoryPool::memory_pool) {
//resize memory pool
@@ -151,6 +177,7 @@ class PoolVector {
//if some resize
} else {
+
memfree( old_alloc->mem );
old_alloc->mem=NULL;
old_alloc->size=0;
@@ -190,7 +217,7 @@ class PoolVector {
if (!alloc)
return;
- if (!alloc->refcount.unref()) {
+ if (alloc->refcount.unref()==false) {
alloc=NULL;
return;
}
@@ -199,7 +226,8 @@ class PoolVector {
{
int cur_elements = alloc->size/sizeof(T);
- Write w;
+ Write w = write();
+
for (int i=0;i<cur_elements;i++) {
w[i].~T();
@@ -585,7 +613,7 @@ Error PoolVector<T>::resize(int p_size) {
} else {
{
- Write w;
+ Write w = write();
for (int i=p_size;i<cur_elements;i++) {
w[i].~T();