summaryrefslogtreecommitdiff
path: root/src/common/dumb_ptr.hpp
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-05-15 15:48:59 -0700
committerBen Longbons <b.r.longbons@gmail.com>2013-05-15 18:56:01 -0700
commitfd00d50574064db9edfcccc4286ed8f1b55b185a (patch)
tree83119340636346a6b7b3d455bae559a9edbe7714 /src/common/dumb_ptr.hpp
parent6ffe0682ab798155129f53b768cb881eac730a1f (diff)
downloadtmwa-fd00d50574064db9edfcccc4286ed8f1b55b185a.tar.gz
tmwa-fd00d50574064db9edfcccc4286ed8f1b55b185a.tar.bz2
tmwa-fd00d50574064db9edfcccc4286ed8f1b55b185a.tar.xz
tmwa-fd00d50574064db9edfcccc4286ed8f1b55b185a.zip
Alter memory management in login server
Diffstat (limited to 'src/common/dumb_ptr.hpp')
-rw-r--r--src/common/dumb_ptr.hpp32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/common/dumb_ptr.hpp b/src/common/dumb_ptr.hpp
index d0b35f2..91293c6 100644
--- a/src/common/dumb_ptr.hpp
+++ b/src/common/dumb_ptr.hpp
@@ -21,6 +21,8 @@
#include "sanity.hpp"
+#include <algorithm>
+
// unmanaged new/delete-able pointer
// should be replaced by std::unique_ptr<T>
template<class T>
@@ -64,11 +66,11 @@ public:
}
explicit
- operator bool()
+ operator bool() const
{
return impl;
}
- bool operator !()
+ bool operator !() const
{
return !impl;
}
@@ -95,12 +97,12 @@ public:
}
void new_(size_t z)
{
- impl = new T[z];
+ impl = new T[z]();
}
static
dumb_ptr<T[]> make(size_t z)
{
- return dumb_ptr<T[]>(new T[z], z);
+ return dumb_ptr<T[]>(new T[z](), z);
}
void forget()
{
@@ -108,17 +110,35 @@ public:
sz = 0;
}
+ size_t size() const
+ {
+ return sz;
+ }
+ void resize(size_t z)
+ {
+ if (z == sz)
+ return;
+ T *np = new T[z]();
+ // not exception-safe, but we don't have a dtor anyway
+ size_t i = std::min(z, sz);
+ while (i-->0)
+ np[i] = std::move(impl[i]);
+ delete[] impl;
+ impl = np;
+ sz = z;
+ }
+
T& operator[](size_t i) const
{
return impl[i];
}
explicit
- operator bool()
+ operator bool() const
{
return impl;
}
- bool operator !()
+ bool operator !() const
{
return !impl;
}