mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-03 12:21:23 +00:00
this is allow custom allocator for obj-api structs/tables. (#4520)
added "native_custom_alloc" attribute to tables/structs, eg.
table parent_table( native_custom_alloc:"custom_alloc_name" ) {
...
}
with a custom allocator defined as
template <typename T> class custom_alloc_name : public std::allocator<T> {
public:
typedef T* pointer;
template <class U>
struct rebind {
typedef custom_alloc_name<U> other;
};
pointer allocate(const std::size_t n) {
return ....;
}
void deallocate(T* ptr, std::size_t n) {
...
}
custom_alloc_name() throw() {}
template <class U> custom_alloc_name(const custom_alloc_name<U>&) throw() {}
};
};
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
ba08b0ec02
commit
53a897731e
@@ -676,6 +676,10 @@ CheckedError Parser::ParseField(StructDef &struct_def) {
|
||||
}
|
||||
}
|
||||
|
||||
auto field_native_custom_alloc = field->attributes.Lookup("native_custom_alloc");
|
||||
if (field_native_custom_alloc)
|
||||
return Error("native_custom_alloc can only be used with a table or struct definition");
|
||||
|
||||
field->native_inline = field->attributes.Lookup("native_inline") != nullptr;
|
||||
if (field->native_inline && !IsStruct(field->value.type))
|
||||
return Error("native_inline can only be defined on structs'");
|
||||
|
||||
Reference in New Issue
Block a user