Idea #1 on integrating RC with GC

Namespace rswhite4 at googlemail.com
Wed Feb 5 11:35:58 PST 2014


On Wednesday, 5 February 2014 at 19:15:41 UTC, Adam D. Ruppe 
wrote:
> On Wednesday, 5 February 2014 at 19:04:10 UTC, Namespace wrote:
>> Would it not be possible to add an "int rc" to the internal 
>> Array struct? So that int[] arr = [1, 2, 3]; is ref counted 
>> per default?
>
> Please no (it'd also have to be int* rc btw). This makes slices 
> fatter than they need to be.
>
> We should be looking at reducing costs, not shuffling them 
> around or adding to them.

Only if you change the current implementation from this:
----
struct Array {
	void* ptr;
	size_t length;
}
----
to this:
----
struct Array {
	void* ptr;
         int* rc;
	size_t length;
}
----
But we could also implement it like this:
----
struct Array {
	static struct Payload {
		void* ptr;
		int* rc;
	}

	Payload* p;
	size_t length;
}
----
with the same costs.


More information about the Digitalmars-d mailing list