blob: d6b16499df430750b0fbd30ade55d548ebad98ac [file] [log] [blame]
Carl Shapiro1fb86202011-06-27 17:43:13 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2// Author: cshapiro@google.com (Carl Shapiro)
3
4#ifndef ART_SRC_HEAP_H_
5#define ART_SRC_HEAP_H_
6
7#include "src/globals.h"
8#include "src/object.h"
9
10namespace art {
11
12class Heap {
13 public:
Carl Shapiro565f5072011-07-10 13:39:43 -070014 static Class* AllocClass() {
15 byte* raw = new byte[sizeof(Class)]();
Carl Shapiro1fb86202011-06-27 17:43:13 -070016 return reinterpret_cast<Class*>(raw);
17 }
Carl Shapiro5fafe2b2011-07-09 15:34:41 -070018
19 static CharArray* AllocCharArray(size_t length) {
20 size_t size = sizeof(Array) + length * sizeof(uint16_t);
21 byte* raw = new byte[size]();
22 return reinterpret_cast<CharArray*>(raw);
23 }
24
25 static String* AllocString() {
26 size_t size = sizeof(String);
27 byte* raw = new byte[size]();
28 return reinterpret_cast<String*>(raw);
29 }
30
31 static String* AllocStringFromModifiedUtf8(const char* data) {
32 String* string = AllocString();
33 uint32_t count = strlen(data); // TODO
34 CharArray* array = AllocCharArray(count);
35 string->array_ = array;
36 string->count_ = count;
37 return string;
38 }
Carl Shapiro1fb86202011-06-27 17:43:13 -070039};
40
41} // namespace art
42
43#endif // ART_SRC_HEAP_H_