• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tries and Freelists  RSS feed

 
Ted Gress
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was wondering if it is possible to implement a freelist in Java? I guess it would have to work with or bypass the garbage collector in some way. Just curious, that's all.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's a freelist? Never heard of it.
You can disable garbage collection by retaining hard references to all objects; you doubtless know that already. Whether that is a good idea is a different matter.

Question too scary for this forum: moving to the “general” forum.
 
Ted Gress
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A freelist is used to allocate a pool of memory that can be recycled so memory doesn't need to be reallocated over and over again.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably can implement that, but you will still have garbage collection problems because all the objects removed from it will still exist in the heap. The concept behind Java® is that it uses an automatic heap.
If you had a reversible Turing machine, you could consider writing objects onto the tape and then winding the tape back when they are no longer required.
 
Ted Gress
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah. Let me pick one up at Best Buy
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait a bit; they will come down by 25% after Christmas
 
Ted Gress
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LOL @Campbell
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I vaguely remember that there are Java caching frameworks which access a big lump of memory which is outside of the JVM's purview and use that for caching objects. I can't remember what technology they use to do that but probably if you poked around the documentation for some of them, you might find out.
 
Ted Gress
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Paul that seems to be exactly what I'm talking about.
I would like to pool memory so the garbage collector doesn't have as much work to do later on when the objects go out of scope.
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a particular reason why you want to do that?
 
Ted Gress
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be honest I'm not sure. The code I'm translating is C/C++ so I guess it is more appropriate to that. There are a lot of objects that would be going in and out of scope since I'm hotloading them according to the map. I just figured it would be a lot of work for the garbage collector and the pooled memory in the C/C++ code might work better. I'm not married to the idea, just wondering if it was possible.
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you'd have to replicate what the garbage collector was doing, wouldn't you? Seems to me it's kind of like "I think my electricity bills are too high so I'll build a nuclear power plant in my basement and produce my own electricity."
 
Ted Gress
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the objects go out of scope the garbage collector would take over imho. But if we are using metaphors, its more like we make too much trash, maybe we should recycle.
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you could certainly try to reuse objects rather than letting them go out of scope. But that's extra work which I wouldn't bother doing until I found out that the garbage collection was costing too much.
 
Ted Gress
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. That's why I was trying to figure out how to pool
memory -- so I could reuse objects instead of relying on the garbage collector to allocate and discard and reallocate. If I could pool memory like I can in C/C++ I could reuse the objects that are generated fairly easily. I'm just trying to make things as efficient as possible. IMHO.
 
Ted Gress
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only problem with trying to pool memory like I was, was I was trying to do it using objects and downcasting them, which isn't possible (I was 99% sure of this but thought I'd post anyway)

So I was trying to do:
public void getNewObject()
{
...
Object t = new Object()
return t;
}
then returning from that method call:

String string = getNewObject()

Which clearly doesn't work.
 
Ted Gress
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops..that's supposed to be:

public Object getNewObject()
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At this point I'd say you haven't got the Java vocabulary to talk about what you want to do. I'd say your idea of pooling memory to save on garbage collection is way above your level right now.
 
Ted Gress
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are wrong. I've been programming in Java for years. I'm sorry but I take that as an insult.
 
Ted Gress
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
12 years to be exact.
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ted Gress wrote:I think you are wrong. I've been programming in Java for years. I'm sorry but I take that as an insult.


If you take it as an insult then I apologize. I had no idea it was possible to program in Java for 12 years and not understand casting. But still, if you don't understand casting then I still think you aren't going to be able to write a caching system to avoid garbage collection.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!