OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COURGETTE_MEMORY_ALLOCATOR_H_ | 5 #ifndef COURGETTE_MEMORY_ALLOCATOR_H_ |
6 #define COURGETTE_MEMORY_ALLOCATOR_H_ | 6 #define COURGETTE_MEMORY_ALLOCATOR_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 // Complement of UncheckedNew(): destructs |object| and releases its memory. | 71 // Complement of UncheckedNew(): destructs |object| and releases its memory. |
72 template <class T> | 72 template <class T> |
73 void UncheckedDelete(T* object) { | 73 void UncheckedDelete(T* object) { |
74 if (object) { | 74 if (object) { |
75 object->T::~T(); | 75 object->T::~T(); |
76 free(object); | 76 free(object); |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 // A deleter for scoped_ptr that will delete the object via UncheckedDelete(). | 80 // A deleter for std::unique_ptr that will delete the object via |
| 81 // UncheckedDelete(). |
81 template <class T> | 82 template <class T> |
82 struct UncheckedDeleter { | 83 struct UncheckedDeleter { |
83 inline void operator()(T* ptr) const { UncheckedDelete(ptr); } | 84 inline void operator()(T* ptr) const { UncheckedDelete(ptr); } |
84 }; | 85 }; |
85 | 86 |
86 #if defined(OS_WIN) | 87 #if defined(OS_WIN) |
87 | 88 |
88 // Manages a read/write virtual mapping of a physical file. | 89 // Manages a read/write virtual mapping of a physical file. |
89 class FileMapping { | 90 class FileMapping { |
90 public: | 91 public: |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 protected: | 497 protected: |
497 T* buffer_; | 498 T* buffer_; |
498 size_t size_; // how much of the buffer we're using. | 499 size_t size_; // how much of the buffer we're using. |
499 size_t alloc_size_; // how much space we have allocated. | 500 size_t alloc_size_; // how much space we have allocated. |
500 Allocator alloc_; | 501 Allocator alloc_; |
501 }; | 502 }; |
502 | 503 |
503 } // namespace courgette | 504 } // namespace courgette |
504 | 505 |
505 #endif // COURGETTE_MEMORY_ALLOCATOR_H_ | 506 #endif // COURGETTE_MEMORY_ALLOCATOR_H_ |
OLD | NEW |