• Advertisement

arkmaster

Member
  • Content count

    25
  • Joined

  • Last visited

Community Reputation

122 Neutral

About arkmaster

  • Rank
    Member
  1. Calling programs from within java

    Oh, so is Runtime.exec(...) non-blocking? i.e. it doesn't wait for the process to terminate before passing control back to the JVM?
  2. it actually might have been that memory that originally was in the swap space was being loaded into ram, therefore making the memory usage to be much higher.
  3. Hey, does anyone here know a general method to start a process from within java, but to redirect the output of the program in real time (i.e. while it is still running) to, say, a textbox component in a GUI? i.e. suppose for some reason i'd want to call a program that outputs the time to stdout every 2 minutes. how would i start the program from a java class, but make sure the output of the program is handled by my java class, and not by opening a terminal window? any help will be appreciated. edit; actually, a more clear example would be something like this: i want to be able to implement a feature using Java similar to that in many IDE for programming languages in which you can run your code and have the output captured within the IDE. [Edited by - arkmaster on June 26, 2006 2:21:03 PM]
  4. well, one advantage of using small files would be that if you needed to patch a part of the engine, or wanted to make a method more efficient, you wouldnt have to re-compile all the code - you'd only need to recompile a small subset of code and switch in that component with your engine.
  5. Hey, I've begun to notice something like this with large objects that I serialize in Java: -Suppose a program is using 50 megs of memory before serialization -All the objects are serialized in order to 'save the state' of the program, if we wanted to restart the program from a given moment in time. It creates a file 18 megs in size. -Upon deserialization, the program is using almost 100 megs of memory! Has anyone noticed this type of problem before, or is it something I'm doing wrong with the way I'm serializing objects...to me it doesnt make sense that if I am essentially loading the state of a program thats been saved to file for my memory usage to be so much higher. Any insights will be appreciated.
  6. Hey all, I've been programming part of a project that performs simulations in Java lately, and one of the things we've implemented lately is a feature to save the state of the simulation at various points in time, due to the amount of time it takes to run any given simulation. I have replaced a Vector object in the engine with a new class I made that is intended to reduce memory usage by swapping out portions to disk. However, it seems that with this new class, if I try to load a state file of the engine, the resumed simulation will be using a lot more memory than if I had let the engine run continuously..this was not a problem before replacing the Vector class. I figure it may have something to do with the object serialization/deserialization code but I'm not sure what.., so I'm going to go ahead and post that here. However, if anyone knows any general reasons why object deserialization in Java can eat up a lot of memory, please let me know. EDIT: If anyone thinks seeing the rest of class's code would help, please let me know. private void writeObject(ObjectOutputStream out) throws IOException { //save statics out.defaultWriteObject(); out.writeInt(globalInstanceCount); out.writeObject(tmpPath); //load all the pma files we created and write them as well for (long i = (totalRemovedSize/ elementsInMemory) + 2; i <= ((totalAddedSize-1)/elementsInMemory) - 1; i++) { String filename = tmpPath + "arrayInst" + currentInstanceCount + "_tmpNum" + i + ".pma"; out.writeObject(readArrayFromFile(filename)); } } private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); //restore statics globalInstanceCount = in.readInt(); tmpPath = (String)in.readObject(); for (long i = (totalRemovedSize/ elementsInMemory) + 2; i <= ((totalAddedSize-1)/elementsInMemory) - 1; i++) { String filename = tmpPath + "arrayInst" + currentInstanceCount + "_tmpNum" + i + ".pma"; //PacketArray writeArray = (PacketArray)in.readObject(); //writeArrayToFile(writeArray, filename); writeArrayToFile((PacketArray)in.readObject(), filename); } } private PacketArray readArrayFromFile(String filename) { PacketArray returnArray = null; try { FileInputStream in = new FileInputStream(filename); ObjectInputStream s = new ObjectInputStream(in); returnArray = (PacketArray)s.readObject(); } catch (FileNotFoundException e) { System.err.println("FileNotFoundException: " + e.getMessage()); System.err.println("Cannot load file, aborting..."); System.exit(0); } catch (IOException e) { System.err.println("IOException: " + e.getMessage()); System.err.println("Aborting..."); System.exit(0); } catch (ClassNotFoundException e) { System.err.println("ClassNotFoundException: " + e.getMessage()); System.err.println("Aborting..."); System.exit(0); } if (returnArray == null) { System.err.println("Null array...this shouldn't happen."); } return returnArray; } private void writeArrayToFile(PacketArray packetArray, String filename) { try { FileOutputStream out = new FileOutputStream(filename); ObjectOutputStream s = new ObjectOutputStream(out); s.writeObject(packetArray); s.flush(); s.close(); out.close(); } catch (FileNotFoundException e) { System.err.println("FileNotFoundException: " + e.getMessage()); } catch (IOException e) { System.err.println("IOException: " + e.getMessage()); } } [Edited by - arkmaster on June 13, 2006 9:57:16 AM]
  7. Mutexes and DuplicateHandle?

    Ah. That would work. I should probably actually be using Events for what I'm trying to do, instead of mutexes..I was implementing something that would wait until a server app's message thread received a new message. I could just set an event for this. Thanks for the help!
  8. Mutexes and DuplicateHandle?

    I am calling a function from Thread A which starts Thread B, however, I want to be sure that Thread B is owning the mutex object before the function returns back to Thread A. On second thought, I suppose I could just call CreateMutex from Thread B, instead of having it created in Thread A, but I am still curious as to whether or not there is another way of going about doing this, because I would still prefer that the mutex was created in Thread A.
  9. Mutexes and DuplicateHandle?

    oh...so is there any way that from thread A i can call a function that causes thread B to be in ownership of a mutex object? thanks for clearing that up about DuplicateHandle though.
  10. Hi, I was wondering how I would go about passing ownership of a mutex object from a source thread to a target thread, with the code for this in the source thread. I believe I need to use DuplicateHandle(...) for this, but I'm not exactly sure how that would work..I'm new to Windows programming. Any help would be appreciated.
  11. ok never mind, i've solved my problem...apparently i needed to define some of my functions as const to work correctly i.e long GetSize() const;
  12. oh this may help with figuring out the problem... //GetSize() is a public function of class DL_List<T> defined: //long GetSize(); template<class T> DL_List<T>::DL_List(const DL_List<T> &init) { long test_size = init.GetSize(); //ERROR COMPILING HERE DL_ListNode<T>* currptr = init.firstptr; while (currptr) { T data = currptr->data; AddToBack(data); currptr = currptr->nextptr; } } when compiling this, i get the following error message: error C2662: 'GetSize' : cannot convert 'this' pointer from 'const class DL_List<float>' to 'class DL_List<float> &' i suppose these two problems might be related to each other...and this current problem is a little less vague than my previous one. Anyone know why this could be happening? Greatly appreciate the help.
  13. the thing that really confuses me is that when i run the debugger, it says 'size' value is something like 1258021. But when i attempt to modify it in the copy constructor, it executes the statement without any errors, but the value stays unchanged.
  14. C++ question: mainly about classes

    declare the classes beforehand: class First; class Second; class First { Second* ptr; }; etc etc. [Edited by - arkmaster on December 24, 2004 10:22:38 PM]
  15. I'm calling a function that uses call by value... ex: DL_List<float> list; mean(list); I do realize that I could avoid the problem by just modifying the function's definition to take a pointer, but then I won't know why I'm having problems...besides, I'll probably need the copy constructor for a more legit. reason later.
  • Advertisement