加载OpenGL文件时使用的RAM非常大

时间:2017-03-18 23:26:03

标签: java memory ram

所以我有一个LWJGL程序加载实体的配置文件,当我加载一个29kb的文件时,ram从正常情况下增加了大约200mb(总共300mb)我不知道该怎么做或者为什么它正在发生。

这是我的完整文件解析代码:

FileReader isr = null;
    File file = new File(CONTAINER + file_name + BMEF);
    String line = null;
    try {
        isr = new FileReader(file);
    } catch (FileNotFoundException e) {
        System.err.println("No BMEF file found in the given context of; BMEF:" + BMEF + ", CONTAINER:" + CONTAINER + ", FILE NAME:" + file_name + ", FULL DIRECTORY USED:" + file);
    }
    BufferedReader reader = new BufferedReader(isr);
    strings = new HashMap<String,String>();
    float_arrays = new HashMap<String,float[]>();
    int_arrays = new HashMap<String,int[]>();
    try {
        String name = null;
        String current = "";
        short type = -1;
        short stage = 0;
        while (true) {
            System.out.println(current);
            line = reader.readLine();
            if(line == null){
                break;
            }
            for(char c : line.toCharArray()){
                current += c;
                if(stage == 0){
                    if(c == ';'){
                        current = current.substring(0, current.length()-1);
                        name = current;
                        current = "";
                        stage++;
                    }
                }else if(stage == 1){
                    if(c == '<'){
                        current = current.substring(0, current.length()-1);
                        if(current.equals(STRING)){
                            type = 0;
                        }else if(current.equals(INT_ARRAY)){
                            type = 1;
                        }else if(current.equals(FLOAT_ARRAY)){
                            type = 2;
                        }else{
                            System.err.println("NO SUCH TYPE: '" + current + "'");
                            System.exit(-1);
                        }
                        current = "";
                        stage++;
                    }
                }else if(stage == 2){
                    if(c == '>'){
                        current = current.substring(0, current.length()-1);
                        if(type == 0){
                            strings.put(name, current);
                        }else if(type == 1){
                            String[] string_arr = current.split(",");
                            int[] out = new int[string_arr.length];
                            for(int i = 0; i < string_arr.length; i++){
                                out[i] = Integer.parseInt(string_arr[i]);
                            }
                            int_arrays.put(name, out);
                        }else if(type == 2){
                            String[] string_arr = current.split(",");
                            float[] out = new float[string_arr.length];
                            for(int i = 0; i < string_arr.length; i++){
                                out[i] = Float.parseFloat(string_arr[i]);
                            }
                            float_arrays.put(name, out);
                        }
                        name = null;
                        current = "";
                        type = -1;
                        stage = 0;
                    }
                }
            }
        }
    } catch (IOException e) {
        System.err.println("An error was encounter whilst reading " + file_name + '.' + BMEF + "the line in use durring this encounter was:'" + line + "'");
    }

0 个答案:

没有答案