sclass ManagedStringList extends AbstractRandomAccessList implements IManagedObject { replace Addr with int. !include #1031662 // IManagedObject mix-in new L list; int physicalLength; class Entry { int ptr; S value; bool changed; *(int *ptr) {} *(S *value) { changed = true; } S value() { if (value == null && ptr != 0) value = mem.readString(ptr); ret value; } void setValue(S s) { value = s; changed = true; } } public int size() { ret l(list); } int arrayStart() { ret addr+2; } int elementAddr(int i) { ret arrayStart()+i; } // read from memory *(ManagedIntObjects_v1 *mem, Addr *addr) { physicalLength = mem.get(addr); int size = mem.get(addr+1); list = emptyList(size); for i to size: list.add(new Entry(mem.get(elementAddr(i)))); } *(ManagedIntObjects_v1 *mem, LS initialData) { fOr (S s : initialData) add(s); flush(); } public void set(int i, S s) { Entry e = list.get(i); e.setValue(s); } public S get(int i) { ret list.get(i).value(); } public bool add(S s) { list.add(new Entry(s)); } void flush { ensureCapacityInternal(size()); mem.set(addr+1, size()); int n = size(); for i to n: { Entry e = list.get(i); if (e.changed) { // release strings here if they are owned e.ptr = mem.newString(e.value); e.changed = false; } mem.set(elementAddr(i), e.ptr); } } void ensureCapacityInternal(int minCapacity) { if (physicalLength < minCapacity) grow(minCapacity); } private void grow(int minCapacity) { int oldCapacity = physicalLength; int newCapacity = oldCapacity + (oldCapacity >> 1); if (newCapacity - minCapacity < 0) newCapacity = minCapacity; long oldAddr = addr, oldSize = objectSize(); physicalLength = newCapacity; setAddr(mem.realloc(addr, objectSize())); mem.set(addr, physicalLength); } // GC handling public void scanForCollection(IManagedObjectCollector gc) { gc.noteObject(addr, objectSize()); int n = size(); for i to n: gc.noteString(mem.get(elementAddr(i))); } int objectSize() { ret 2+physicalLength; } }