[Issue 4681] Appender access violation
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Aug 26 05:20:23 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4681
--- Comment #11 from nfxjfg at gmail.com 2010-08-26 05:20:08 PDT ---
This is still full of dirty runtime calls and attempts to emulate half of
lifetime.d (though the worst part is commented).
Why doesn't it simply use the D standard way to re-allocate an array, and then
use array.capacity to see how much can be safely appended?
Something along the lines of:
private struct Data {
T[] arr;
size_t user_length;
}
Data _data;
void put(T item) {
if (_data.user_length == arr.length) {
size_t newcapacity = something larger than user_length;
reallocate(newcapacity);
}
_data.arr[_data.user_length++] = item;
}
void reallocate(size_t newcapacity) {
_data.arr.length = newcapacity;
//include the data "overallocated" by the runtime into the array
size_t realcap = _data.arr.capacity;
_data.arr.length = realcap;
}
T[] data() {
T[] arr = _data.arr[0.._data.user_length];
_data = _data.init;
assumeSafeAppend(arr);
return arr;
}
Or did I overlook something.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list