what is aTTY point to by in the New method ? what is it use for? purpose ?
the document said: “that can hold the pointer for the maintained object.” i don’t understand, the pointer return from malloc isn’t the object ? why another pointer?
2.the size of the record is always suppose to be sizeof(Intptr)+aSize ?
Lifetime strategies can be used for external types. In cases like that, it would be used to create objects. The boehmgc strategy (default GC) is implemented like this:
For this kind of work where the struct you want to define operators for is the same struct, it might be better to use regular operators for lifetime like I do in Olestring:
aTTY is TypeInfo. But I think lifetime strategies isn’t a good fit for your usecase. You use them when defining the lifetime for “other” types, like classes or structs.
If I read your code right you need an object that manages an external pointer. Regular operators is a better fit (but correct me if I am wrong). something like:
public struct GdiObject {
private static IntPtr value;
public GdiObject(IntPtr value) {this.value = value; } // regular ctor
public this Copy(GdiObject other) {
// copy ctor
this.value = CloneGdiObject(other.value);
}
public static operator = (ref OleString dest, ref OleString source) { }}
public ~() { cleanup }
}
Note that this requires the next version as I just found that hte = operator was only supported in Oxygene, not Hydrogene.
i try to wrap around the windows Gdi+ library, many of its classes are subclass from the GdiplusBase, use its own memory management. as the follow c++ code.
i can just copy & modify the code from RC strategy in pascal, but when i tried to implement in c# it looks difficult. 2 problems here. 1) as u mentioned, operator = in c# is a problem. 2) how to implement finalizer in c# ?
You really shouldn’t be using the lifetime stuff at all for this but something like this:
public struct GdiObject {
private static IntPtr value;
public GdiObject(IntPtr value) {this.value = value; } // regular ctor
public this Copy(GdiObject other) {
// copy ctor
this.value = CloneGdiObject(other.value);
}
public static operator = (ref GdiObject dest, ref GdiObject source) { }}
public ~() { cleanup }
}
with last fridays build.
Then it works right away. Now if you do ever need a lifetime override, something like: [Assembly: RemObjects.Elements.System.LifetimeStrategyOverrideAttribute(typeOf(rtl.winrt.HSTRING), typeOf(HString_Helper))]
could work; But really thats mostly for overriding it. Above code matches the c++ better.
public struct GdiObject {
private static IntPtr value;
public GdiObject(IntPtr value) {this.value = value; } // regular ctor
public this Copy(GdiObject other) {
// copy ctor
this.value = CloneGdiObject(other.value);
}
public static bool operator = (ref GdiObject dest, ref GdiObject source) { }
public ~GdiObject() { }
}
ck, how can i invoke Copy method ? i tried following code, it shows error: Parameter labels do not match. Parameter 1 is unlabeled, but should should be labeled “withCopy” in call to “MyObject Copy(MyObject src)”