Crash....Println an array of objects
in
Programming Questions
•
1 year ago
Hey guys!
When I try and println an array of ~41,000 place objects my program crashes. I tried increasing the max available memory to 500MB when I got an "out of memory" error but it is still happening. Any brainstorms on how to fix it?
My system:
4GB RAM, Intel dual core, 64-bit
Thank you!
When I try and println an array of ~41,000 place objects my program crashes. I tried increasing the max available memory to 500MB when I got an "out of memory" error but it is still happening. Any brainstorms on how to fix it?
My system:
4GB RAM, Intel dual core, 64-bit
Thank you!
- String[] data;
- Place[] places;
- int totalCount, zip;
- int placeCount = 0;
- float Xmin, Xmax, Ymin, Ymax, x, y;
- float mapX1, mapX2, mapY1, mapY2;
- String name;
- color backgroundColor = color(152, 151, 141);
- color highlightedColor = color(247, 237, 25);
- color unhighlightedColor = backgroundColor;
- void setup() {
- size(720, 453, P3D);
- mapX1 = 30.0;
- mapX2 = width - mapX1;
- mapY1 = 20.0;
- mapY2 = height - mapY1;
- readData(data); //output is Place(zip name x y)
- }
- public void draw() {
- /*background(backgroundColor);
- //for(int i=0; i<placeCount; i++) {
- //places[i].draw();
- }*/
- }
- float TX(float x) {
- return map(x, Xmin, Xmax, mapX1, mapX2);
- }
- float TY(float y) {
- return map(y, Ymin, Ymax, mapY1, mapY2);
- }
- void readData(String[] data) {
- data = loadStrings("clean.tsv");
- parseInfo(data[0]);
- places = new Place[data.length];
- for(int i=1; i<data.length; i++) {
- places[placeCount] = parsePlace(data[i]);
- placeCount++;
- }
- for(int j=0; j<places.length; j++) {
- println(places[j]);
- }
- }
- //read header line
- void parseInfo(String head) {
- String[] pieces = split(head, TAB);
- //totalCount = int(pieces[0]); tC = 41859 but data.length = 41705
- Xmin = float(pieces[1]);
- Xmax = float(pieces[2]);
- Ymin = float(pieces[3]);
- Ymax = float(pieces[4]);
- }
- Place parsePlace(String pLine) {
- String[] pieces = split(pLine, TAB);
- zip = int(pieces[0]);
- x = float(pieces[1]);
- y = float(pieces[2]);
- name = pieces[3] + ", " + pieces[4];
- return new Place(zip, name, x, y);
- }
- class Place {
- String name;
- int zip;
- float x;
- float y;
- Place(int zip, String name, float x, float y) {
- this.name = name;
- this.zip = zip;
- this.x = x;
- this.y = y;
- }
- void draw() {
- float xx = TX(x);
- float yy = TY(y);
- //set(xx, yy, highlightedColor);
- println(xx + " " + yy + " " + name);
- }
- }
1