gc<Object> RecordObject::create(gc<RecordType> type, const Array<gc<Object> >& stack, int startIndex) { // Allocate enough memory for the record and its fields. void* mem = Memory::allocate(sizeof(RecordObject) + sizeof(gc<Object>) * (type->numFields() - 1)); // Construct it by calling global placement new. gc<RecordObject> record = ::new(mem) RecordObject(type); // Initialize the fields. for (int i = 0; i < type->numFields(); i++) { record->fields_[i] = stack[startIndex + i]; } return record; }
gc<DynamicObject> DynamicObject::create(gc<ClassObject> classObj) { ASSERT(classObj->numFields() == 0, "Class cannot have fields."); // Allocate enough memory for the object. void* mem = Memory::allocate(sizeof(DynamicObject)); // Construct it by calling global placement new. return ::new(mem) DynamicObject(classObj); }