Skip to main content
gamedev.net
🔒 Locked

Java Arrays

Started by template Nov 20, 2003 at 4:09 PM 6 replies 1.1k views
Original Post
template
template
Forgive me if this question is stupid but i''m used to C++. If I have a normal array of say ints how can I delete the array i.e. set its length to 0? In C++ I would just use the delete keyword but since Java has no delete keyword I have no idea how to do this. Any help is much appreciated.
MrPoopypants
MrPoopypants
three words... Automatic Garbage Collection

And also, use Array Lists to make it easier
(0110101101000110)The Murphy Philosophy: Smile . . . tomorrow will be worse.
template
template
Heh, that''s where my problem lies.

The lecturer insists that we write a method to empty the array and I have absolutely no idea how to unless I use an ArrayList (which we haven''t yet been taught but I have experience with them from other languages i.e. C#).

And yes, I know asking for help with homework isn''t encouraged but i''m not asking/nor expecting anyone to write the program for me, I just need a nod in the right direction.
Raghar
Raghar
actually it's something like this

 

myarray2=null;

//you might try to call gc here, but don't forget GC will take it just as a recomendaton.


or

MyThreadU.nullAndPrepareArrayForTheRecyclingInTheStack(myarray2);


First is for saving memory. Second for saving CPU cycles and fragmentation of memory. This means it's "only" way how to do this in tight loop and don't run as a dog.


[edited by - Raghar on November 20, 2003 5:26:18 PM]
Raghar
Raghar
Your teacher does have so much free time. Ask him how many work about AI did and published in last few years and if he will do at least some paper. He migh concentrate on actual research and have less time to think of something like that stupidity.
He should rather teach you some memory management in Java. GC do ONLY half of work and some programmers are doing it much more difficult for GC.

template
template
Thanks for the help.

The lecturer is a crap teacher, almost the entire class is struggling with Java, although i'm lucky to have experience with C++ and C#.

A lot of my classmates have filed complaints against her because of this. And yes, she does have far too much spare time because today she had brought in an advent calendar with chocolates in it to "help" demonstrate how stacks work.

She also made some class members stand up at the front of the classroom and had about 6 people representing an array. She then got another person to go through them all and check what their names were. This was to demonstrate searching through an array.

It's unbelievable how dire her teaching skills are. And this is supposed to be the equivalent to 2nd year degree work. Pfft.

I've decided to tell her tomorrow that the reason I didn't write an empty() method was because Java has automatic garbage collection. If she then tells me to do it anyway i'll complain about her wasting time. The class is already a few weeks behind schedule because of her terrible teaching, she has been trying to explain stacks for the past 2 or 3 weeks ffs.

[edited by - template on November 20, 2003 5:43:43 PM]
Ziphnor
Ziphnor
"I''ve decided to tell her tomorrow that the reason I didn''t write an empty() method was because Java has automatic garbage collection."

But then again, garbage collections only collects stuff which no one is pointing to anymore, so if you dont "drop" you array ref. it wont be collected.
MARS_999
MARS_999
Tell her she should go sell clothes at PCPenny's due to her not understanding things she thinks she has a clue about!!!

I A'cd Java. Still like C++ better....

[edited by - Mars_999 on November 20, 2003 7:15:13 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.