Skip to main content
added 65 characters in body
Source Link

There is potentially unknown number of variables pointing to ("referencing") the same Java array. It cannot be "reallocated" because these references may end up pointing to nothing if it is moved in the memory. A wrapper object is required that is not reallocated so references to it remain valid. This wrapper object can then manage the internal array to what only it has access to.

With C++, it is still possible to get this wrong by creating and retaining pointers into internal values inside the vector: you add one more element, the vector grows and using your pointers is now undefined behavior. However you mostly just need to be aware.

And, yes, C++ does have std::realloc that you may use if find reasonable, even if there are restrictions how to allocate the region, see comment below.

There is potentially unknown number of variables pointing to ("referencing") the same Java array. It cannot be "reallocated" because these references may end up pointing to nothing if it is moved in the memory. A wrapper object is required that is not reallocated so references to it remain valid. This wrapper object can then manage the internal array to what only it has access to.

With C++, it is still possible to get this wrong by creating and retaining pointers into internal values inside the vector: you add one more element, the vector grows and using your pointers is now undefined behavior. However you mostly just need to be aware.

And, yes, C++ does have std::realloc that you may use if find reasonable.

There is potentially unknown number of variables pointing to ("referencing") the same Java array. It cannot be "reallocated" because these references may end up pointing to nothing if it is moved in the memory. A wrapper object is required that is not reallocated so references to it remain valid. This wrapper object can then manage the internal array to what only it has access to.

With C++, it is still possible to get this wrong by creating and retaining pointers into internal values inside the vector: you add one more element, the vector grows and using your pointers is now undefined behavior. However you mostly just need to be aware.

And, yes, C++ does have std::realloc that you may use if find reasonable, even if there are restrictions how to allocate the region, see comment below.

Source Link

There is potentially unknown number of variables pointing to ("referencing") the same Java array. It cannot be "reallocated" because these references may end up pointing to nothing if it is moved in the memory. A wrapper object is required that is not reallocated so references to it remain valid. This wrapper object can then manage the internal array to what only it has access to.

With C++, it is still possible to get this wrong by creating and retaining pointers into internal values inside the vector: you add one more element, the vector grows and using your pointers is now undefined behavior. However you mostly just need to be aware.

And, yes, C++ does have std::realloc that you may use if find reasonable.