A basic PMC appears to contain
flags
of which 8 are private so I could use
a data pointer
which I can use. I am always responsible for freeing anything there(?)
and to do this I need to set the active destroy flag(?)
This flag is not the same as the high priority DOD system(?)
Does the garbage collector ever consider this pointer?
Does it ever chase what it points to?
a pobj_t union
which I can use.
Given that the nature of a C union means that the floating point value
occupies the same space as the pointer, do I need to set flags
depending on whether the pointers point to anything?
The pobj_t union contains one of:
A buffers structure
I'm not sure how to use this, but I'm not sure if I need to.
A pair of pointers
What's the difference between the _struct_val pointer and the
_pmc_val pointer? Is the PMC pointer only allowed to point to other
PMCs, while the other pointer is allowed to point to anything
non-PMC. If not, why are there two pointers? Does on PMC need two?
Does the garbage collector consider both pointers? Does it inspect
whatever they point to?
Do I need to set any flags, or do I just assign pointers to these?
When I'm done, do I need to be careful to assign NULL pointers to
ensure that the GC doesn't think I'm still interested in whatever
object I used to point to?
A pointer to a parrot string
An integer
A floating point value
I think that's all my questioning for now :-)
Nicholas Clark
I will try to answer what I can, based on my current experience making
those array PMCs.
Nicholas Clark wrote:
>a data pointer
> which I can use. I am always responsible for freeing anything there(?)
> and to do this I need to set the active destroy flag(?)
> This flag is not the same as the high priority DOD system(?)
> Does the garbage collector ever consider this pointer?
> Does it ever chase what it points to?
>
>
You are responsible for freeing it by setting the active destroy flag.
If it contains pointers that need to be chased, you are responsible for
supplying a mark function and setting the custom mark flag.
Examples of both of these can be found in fixedstringarray.pmc and
fixedpmcarray.pmc, whereas fixedfloatarray.pmc has an active destroy and
no mark.
You access this through the PMC_data(...) macro, typically passing SELF.
>a pobj_t union
> which I can use.
> Given that the nature of a C union means that the floating point value
> occupies the same space as the pointer, do I need to set flags
> depending on whether the pointers point to anything?
>
>
>The pobj_t union contains one of:
>
>A buffers structure
> I'm not sure how to use this, but I'm not sure if I need to.
>
>A pair of pointers
> What's the difference between the _struct_val pointer and the
> _pmc_val pointer? Is the PMC pointer only allowed to point to other
> PMCs, while the other pointer is allowed to point to anything
> non-PMC. If not, why are there two pointers? Does on PMC need two?
> Does the garbage collector consider both pointers? Does it inspect
> whatever they point to?
> Do I need to set any flags, or do I just assign pointers to these?
> When I'm done, do I need to be careful to assign NULL pointers to
> ensure that the GC doesn't think I'm still interested in whatever
> object I used to point to?
>
>
Not sure, I never used any of this.
>A pointer to a parrot string
>
>An integer
>
>A floating point value
>
>
I know that you can access the integer via PMC_int_val(...) macro.
All of the array classes that I made just use the integer and the data
pointer, but that is because they are really quite simple.
>I think that's all my questioning for now :-)
>
>
Sorry I can't be more helpful.
>Nicholas Clark
>
>
Matt
Well... no. You're not. If the memory hanging off the data pointer
was allocated from one of parrot's managed pools (either free memory
or pmc/buffer header) then you don't have to free it.
You only need to have a destroy function if you've malloc'd memory or
need to actively tear down something, usually a filehandle or
connection to a third-party extension or something.
--
Dan
--------------------------------------it's like this-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk
I'll write up something more detailed later on today, but for now:
>A basic PMC appears to contain
>
>flags
> of which 8 are private so I could use
Yes.
>a data pointer
> which I can use. I am always responsible for freeing anything there(?)
No. Only if you need to take some sort of extraordinary measures.
> and to do this I need to set the active destroy flag(?)
Again, only with extraordinary measures.
> This flag is not the same as the high priority DOD system(?)
Nope.
> Does the garbage collector ever consider this pointer?
Yes, if the right flags are set.
is_PMC_ptr is set if this pointer points to a PMC.
is_buffer_ptr is set if this pointer points to a buffer-like
structure. (Such as a string)
Set them both if the pointer points to a buffer of PMCs.
> Does it ever chase what it points to?
If the right flags are set (namely the two above) yes.
>a pobj_t union
> which I can use.
> Given that the nature of a C union means that the floating point value
> occupies the same space as the pointer, do I need to set flags
> depending on whether the pointers point to anything?
If they point to something parrot needs to track (a buffer, string or
PMC) and you want parrot to do it automatically, yes. I'm going to
have to go dig for that, though, as things have changed a bit since I
last looked.
There's a memory internals document, but I can't spot any document given
an API overview on how to allocate memory this way.
The implication of what you're saying is that the data pointer is checked by
the DOD, and any PMC it points directly to isn't dead.
Nicholas Clark
Yeah, it's all kinda ad-hoc. Needs fixing.
>The implication of what you're saying is that the data pointer is checked by
>the DOD, and any PMC it points directly to isn't dead.
Well... sort of. Checking and cleaning up are two very separate
things here. Parrot may not automatically check (leaving that to your
PMC's custom mark routine) but will automatically clean up. (If
you've not marked in your custom mark routine)
Basically, if the right flags are set, the DOD trace will treat the
pointer as pointing to something it should consider, and
automatically trace into it. If the right flags aren't set it won't,
and your needs to mark it explicitly.
Regardless of anything else, the DOD sweep will reclaim the
PMC/String/Buffer/PObj structures if they aren't marked in the mark
phase, either automatically or by a PMC mark routine, and memory not
pointed to by a live buffer-ish thing will get reclaimed, so if your
PMC with custom stuff hanging off the data pointer dies parrot will
still reclaim its memory and whatnot for you.
I'll create a POD, which hopefully will answer all these questons.
leo
A first draft of F<docs/pmc.pod> is in.
leo