Permalink
Browse files

Add LocalBuffer struct to handle buffer deallocation

This follows the Resource Acquisition Is Initialization (RAII) idiom,
which frees the buffer upon destruction of the object.

Thanks to @evanphx for the idea.
  • Loading branch information...
1 parent 4a23b15 commit 413fbbe4cbe0132c0fb9aa3e1d3fa62db68bbda2 @zaeleus zaeleus committed Apr 12, 2012
Showing with 18 additions and 0 deletions.
  1. +18 −0 vm/util/local_buffer.hpp
View
@@ -0,0 +1,18 @@
+#ifndef RBX_UTIL_LOCAL_BUFFER_HPP
+#define RBX_UTIL_LOCAL_BUFFER_HPP
+
+namespace rubinius {
+ struct LocalBuffer {
+ void* buffer;
+
+ LocalBuffer(size_t size) {
+ buffer = malloc(size);
+ }
+
+ ~LocalBuffer() {
+ free(buffer);
+ }
+ };
+}
+
+#endif

0 comments on commit 413fbbe

Please sign in to comment.