You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicclassImageDataRecordimplementsImageData {
publicstaticBufferedImage[] images;
publicBufferedImagegetImage() {
returnimages[index()];
}
publicvoidsetImage(BufferedImageimage) {
images[index()] = image;
}
// these functions will be added if a reference is needed somewhere in the recordpublicvoidinit(intindex) {
memory.setInt(address(), index);
}
publicintindex() {
returnmemory.getInt(address());
}
publicstaticvoidensureCapacity(intsize) {
images = newBufferedImage[size];
}
publicvoidrelease() {
images[index()] = null;
}
}
The init function gets called every time a record is allocated. The passed index is handled by the RecordAdapter ensuring it is not used by another record of this type. The capacity of the underlying array gets increased by the adapter with a step size of 16. Release() will also be called by the adapter.
This features needs a lot of managing functions in order to be fast, a simple but slow version could look like this.
publicclassImageDataRecordimplementsImageData {
publicstaticMap<Long, BufferedImage> images = newHashMap<>();
publicBufferedImagegetImage() {
returnimages.get(address());
}
publicvoidsetImage(BufferedImageimage) {
images.put(address(), image);
}
// these functions will be added if a reference is needed somewhere in the recordpublicvoidrelease() {
images.remove(address());
}
}
The text was updated successfully, but these errors were encountered:
It should be possible to store references to other Java objects in a record.
The generated source should look like this
The init function gets called every time a record is allocated. The passed index is handled by the RecordAdapter ensuring it is not used by another record of this type. The capacity of the underlying array gets increased by the adapter with a step size of 16. Release() will also be called by the adapter.
This features needs a lot of managing functions in order to be fast, a simple but slow version could look like this.
The text was updated successfully, but these errors were encountered: