• Welcome to Valhalla Legends Archive.
 

Interfaces

Started by Imperceptus, September 25, 2009, 01:57 PM

Previous topic - Next topic

MyndFyre

Quote from: Camel on October 21, 2009, 12:10 PM
A the GC would never have to worry about the equivalent object to a stack-bound struct, because its scope will end within the method, and the GC will therefore not have to 'watch' its life-cycle.
Precisely why it's advantageous.

If I create an array of heap-bound objects and then take a pointer to it, the garbage collector has to "pin" the objects so that they're not relocated during compaction.  If I instead create an array of stack-bound objects, since the stack is not subject to the garbage collector, I can take pointers to them as long as I want without regard or worry about its impact on the GC.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Camel

#31
I don't think you understood what I'm saying at all. If you create an object, and the jitter knows that there's no code path where it can have remote references at the end of its declarative scope, it will create machine code that destroys and deallocates it at the end of its scope instead of sending it to the collector for reference monitoring.

In the example:

int[] getInts() {
    List<Integer> ints = new ArrayList<Integer>(100);
    for(int x = 0; x < 100; x++)
        ints.add(new Integer(x));
    return ints.toArray();
}

the object referenced by ints will never make it to the collector.

The limitation on this enhancement is the same limitation that you'd inherently get with stack-bound data anyways: it can't leave its declarative scope. That completely invalidates any argument for performance gain by putting non-references/primitives in the stack that I can think of.

[edit] Of course, if you pass the object to overridable/external code, the jitter won't be able to perform the enhancement; but I think it's unlikely that someone would choose such a pattern in a time-critical segment of code.

Michael

#32
I am trying to make sense of this, It is better to pass things as whatever they are declared as rather then passing them as just an object?


For example in C#

public void main()
{
string greeting = "hello world";
}

public void DisplayGreeting(string greeting)
{
debug.print(greeting);
}

would be better to do then


public void main()
{
string greeting = "hello world";
}

public void DisplayGreeting(object greeting)
{
debug.print(greeting.tostring());
}


MyndFyre

It's effectively the same thing when dealing with reference types (like string).  When dealing with value types (like int), there's an operation called "boxing" and "unboxing" that has to happen.  You can look up info about boxing/unboxing.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

|