NativeCall -- size of data structure

--000000000000b4600205b7f4782f
Content-Type: text/plain; charset="UTF-8"

Hey Gents,

Hopefully a simple question that I could not find the answer to.

Given the following:

class PROCESSENTRY32 is repr('CStruct') {
    has int32 $.dwSize;
    has int32 $.cntUsage;
    has int32 $.th32ProcessID;
    has Pointer $.th32DefaultHeapID;
    has int32 $.th32ModuleID;
    has int32 $.cntThreads;
    has int32 $.th32ParentProcessID;
    has long $.pcPriClassBase;
    has int32 $.dwFlags;
    HAS Str @.szExeFile[260] is CArray;      # MAX_PATH on windows is 260
};


.... is there is a raku method that gives me the size of this data structure?

In C for example one would use sizeof() to provide the size.  In raku I
could not find the documentation that would provide this information.

Thanks,
Paul Procacci
-- 
__________________

:(){ :|:& };:

--000000000000b4600205b7f4782f
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hey Gents,</div><div><br></div><div>Hopefully a simpl=
e question that I could not find the answer to.</div><div><br></div><div>Gi=
ven the following:<br></div><div><pre style=3D"background-color:rgb(255,255=
,255);color:rgb(8,8,8);font-family:&quot;JetBrains Mono&quot;,monospace;fon=
t-size:9.8pt"><span style=3D"color:rgb(0,51,179)">class </span><span style=
=3D"color:rgb(75,0,130)">PROCESSENTRY32 </span><span style=3D"color:rgb(0,5=
1,179)">is </span><span style=3D"color:rgb(75,0,130)">repr</span>(<span sty=
le=3D"color:rgb(6,125,23)">&#39;CStruct&#39;</span>) {<br>    <span style=
=3D"color:rgb(0,51,179)">has </span><span style=3D"color:rgb(75,0,130)">int=
32 </span><span style=3D"color:rgb(128,0,128)">$.dwSize</span>;<br>    <spa=
n style=3D"color:rgb(0,51,179)">has </span><span style=3D"color:rgb(75,0,13=
0)">int32 </span><span style=3D"color:rgb(128,0,128)">$.cntUsage</span>;<br=
>    <span style=3D"color:rgb(0,51,179)">has </span><span style=3D"color:rg=
b(75,0,130)">int32 </span><span style=3D"color:rgb(128,0,128)">$.th32Proces=
sID</span>;<br>    <span style=3D"color:rgb(0,51,179)">has </span><span sty=
le=3D"color:rgb(75,0,130)">Pointer </span><span style=3D"color:rgb(128,0,12=
8)">$.th32DefaultHeapID</span>;<br>    <span style=3D"color:rgb(0,51,179)">=
has </span><span style=3D"color:rgb(75,0,130)">int32 </span><span style=3D"=
color:rgb(128,0,128)">$.th32ModuleID</span>;<br>    <span style=3D"color:rg=
b(0,51,179)">has </span><span style=3D"color:rgb(75,0,130)">int32 </span><s=
pan style=3D"color:rgb(128,0,128)">$.cntThreads</span>;<br>    <span style=
=3D"color:rgb(0,51,179)">has </span><span style=3D"color:rgb(75,0,130)">int=
32 </span><span style=3D"color:rgb(128,0,128)">$.th32ParentProcessID</span>=
;<br>    <span style=3D"color:rgb(0,51,179)">has </span><span style=3D"colo=
r:rgb(75,0,130)">long </span><span style=3D"color:rgb(128,0,128)">$.pcPriCl=
assBase</span>;<br>    <span style=3D"color:rgb(0,51,179)">has </span><span=
 style=3D"color:rgb(75,0,130)">int32 </span><span style=3D"color:rgb(128,0,=
128)">$.dwFlags</span>;<br>    <span style=3D"color:rgb(0,51,179)">HAS </sp=
an><span style=3D"color:rgb(75,0,130)">Str </span><span style=3D"color:rgb(=
128,0,128)">@.szExeFile[</span><span style=3D"color:rgb(23,80,235)">260</sp=
an><span style=3D"color:rgb(128,0,128)">] </span><span style=3D"color:rgb(0=
,51,179)">is </span><span style=3D"color:rgb(75,0,130)">CArray</span>;     =
 <span style=3D"color:rgb(140,140,140);font-style:italic"># MAX_PATH on win=
dows is 260<br></span>};</pre></div><div><br></div><div>... is there is a r=
aku method that gives me the size of this data structure?</div><div><br></d=
iv><div>In C for example one would use sizeof() to provide the size.=C2=A0 =
In raku I could not find the documentation that would provide this informat=
ion.<br></div><div><br></div><div>Thanks,</div><div>Paul Procacci<br></div>=
<div>-- <br><div dir=3D"ltr" class=3D"gmail_signature" data-smartmail=3D"gm=
ail_signature">__________________<br><br>:(){ :|:&amp; };:</div></div></div=
>

--000000000000b4600205b7f4782f--
0
pprocacci
1/3/2021 12:58:17 AM
perl.perl6.users 1545 articles. 0 followers. Follow

3 Replies
365 Views

Similar Articles

[PageSpeed] 31
Get it on Google Play
Get it on Apple App Store

--000000000000f6671f05b7f48cbe
Content-Type: text/plain; charset="UTF-8"

Apologies.  I just came across it.

nativesizeof is the subroutine you're looking for.

Again, sorry for the noise.

~Paul


On Sat, Jan 2, 2021 at 7:58 PM Paul Procacci <pprocacci@gmail.com> wrote:

> Hey Gents,
>
> Hopefully a simple question that I could not find the answer to.
>
> Given the following:
>
> class PROCESSENTRY32 is repr('CStruct') {
>     has int32 $.dwSize;
>     has int32 $.cntUsage;
>     has int32 $.th32ProcessID;
>     has Pointer $.th32DefaultHeapID;
>     has int32 $.th32ModuleID;
>     has int32 $.cntThreads;
>     has int32 $.th32ParentProcessID;
>     has long $.pcPriClassBase;
>     has int32 $.dwFlags;
>     HAS Str @.szExeFile[260] is CArray;      # MAX_PATH on windows is 260
> };
>
>
> ... is there is a raku method that gives me the size of this data
> structure?
>
> In C for example one would use sizeof() to provide the size.  In raku I
> could not find the documentation that would provide this information.
>
> Thanks,
> Paul Procacci
> --
> __________________
>
> :(){ :|:& };:
>


-- 
__________________

:(){ :|:& };:

--000000000000f6671f05b7f48cbe
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Apologies.=C2=A0 I just came across it.</div><div><br=
></div><div><pre style=3D"background-color:rgb(255,255,255);color:rgb(8,8,8=
);font-family:&quot;JetBrains Mono&quot;,monospace;font-size:9.8pt"><span s=
tyle=3D"color:rgb(0,51,179)">nativesizeof is the subroutine you&#39;re look=
ing for.<br><br></span></pre><pre style=3D"background-color:rgb(255,255,255=
);color:rgb(8,8,8);font-family:&quot;JetBrains Mono&quot;,monospace;font-si=
ze:9.8pt"><span style=3D"color:rgb(0,51,179)">Again, sorry for the noise.<b=
r><br></span></pre><pre style=3D"background-color:rgb(255,255,255);color:rg=
b(8,8,8);font-family:&quot;JetBrains Mono&quot;,monospace;font-size:9.8pt">=
<span style=3D"color:rgb(0,51,179)">~Paul<br></span></pre></div></div><br><=
div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Sat, Jan=
 2, 2021 at 7:58 PM Paul Procacci &lt;<a href=3D"mailto:pprocacci@gmail.com=
">pprocacci@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_qu=
ote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,20=
4);padding-left:1ex"><div dir=3D"ltr"><div>Hey Gents,</div><div><br></div><=
div>Hopefully a simple question that I could not find the answer to.</div><=
div><br></div><div>Given the following:<br></div><div><pre style=3D"backgro=
und-color:rgb(255,255,255);color:rgb(8,8,8);font-family:&quot;JetBrains Mon=
o&quot;,monospace;font-size:9.8pt"><span style=3D"color:rgb(0,51,179)">clas=
s </span><span style=3D"color:rgb(75,0,130)">PROCESSENTRY32 </span><span st=
yle=3D"color:rgb(0,51,179)">is </span><span style=3D"color:rgb(75,0,130)">r=
epr</span>(<span style=3D"color:rgb(6,125,23)">&#39;CStruct&#39;</span>) {<=
br>    <span style=3D"color:rgb(0,51,179)">has </span><span style=3D"color:=
rgb(75,0,130)">int32 </span><span style=3D"color:rgb(128,0,128)">$.dwSize</=
span>;<br>    <span style=3D"color:rgb(0,51,179)">has </span><span style=3D=
"color:rgb(75,0,130)">int32 </span><span style=3D"color:rgb(128,0,128)">$.c=
ntUsage</span>;<br>    <span style=3D"color:rgb(0,51,179)">has </span><span=
 style=3D"color:rgb(75,0,130)">int32 </span><span style=3D"color:rgb(128,0,=
128)">$.th32ProcessID</span>;<br>    <span style=3D"color:rgb(0,51,179)">ha=
s </span><span style=3D"color:rgb(75,0,130)">Pointer </span><span style=3D"=
color:rgb(128,0,128)">$.th32DefaultHeapID</span>;<br>    <span style=3D"col=
or:rgb(0,51,179)">has </span><span style=3D"color:rgb(75,0,130)">int32 </sp=
an><span style=3D"color:rgb(128,0,128)">$.th32ModuleID</span>;<br>    <span=
 style=3D"color:rgb(0,51,179)">has </span><span style=3D"color:rgb(75,0,130=
)">int32 </span><span style=3D"color:rgb(128,0,128)">$.cntThreads</span>;<b=
r>    <span style=3D"color:rgb(0,51,179)">has </span><span style=3D"color:r=
gb(75,0,130)">int32 </span><span style=3D"color:rgb(128,0,128)">$.th32Paren=
tProcessID</span>;<br>    <span style=3D"color:rgb(0,51,179)">has </span><s=
pan style=3D"color:rgb(75,0,130)">long </span><span style=3D"color:rgb(128,=
0,128)">$.pcPriClassBase</span>;<br>    <span style=3D"color:rgb(0,51,179)"=
>has </span><span style=3D"color:rgb(75,0,130)">int32 </span><span style=3D=
"color:rgb(128,0,128)">$.dwFlags</span>;<br>    <span style=3D"color:rgb(0,=
51,179)">HAS </span><span style=3D"color:rgb(75,0,130)">Str </span><span st=
yle=3D"color:rgb(128,0,128)">@.szExeFile[</span><span style=3D"color:rgb(23=
,80,235)">260</span><span style=3D"color:rgb(128,0,128)">] </span><span sty=
le=3D"color:rgb(0,51,179)">is </span><span style=3D"color:rgb(75,0,130)">CA=
rray</span>;      <span style=3D"color:rgb(140,140,140);font-style:italic">=
# MAX_PATH on windows is 260<br></span>};</pre></div><div><br></div><div>..=
.. is there is a raku method that gives me the size of this data structure?<=
/div><div><br></div><div>In C for example one would use sizeof() to provide=
 the size.=C2=A0 In raku I could not find the documentation that would prov=
ide this information.<br></div><div><br></div><div>Thanks,</div><div>Paul P=
rocacci<br></div><div>-- <br><div dir=3D"ltr">__________________<br><br>:()=
{ :|:&amp; };:</div></div></div>
</blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g=
mail_signature">__________________<br><br>:(){ :|:&amp; };:</div>

--000000000000f6671f05b7f48cbe--
0
pprocacci
1/3/2021 1:03:56 AM
On 1/2/21 4:58 PM, Paul Procacci wrote:
> Hey Gents,
>=20
> Hopefully a simple question that I could not find the answer to.
>=20
> Given the following:
>=20
> class PROCESSENTRY32 is repr('CStruct') {
>      has int32 $.dwSize;
>      has int32 $.cntUsage;
>      has int32 $.th32ProcessID;
>      has Pointer $.th32DefaultHeapID;
>      has int32 $.th32ModuleID;
>      has int32 $.cntThreads;
>      has int32 $.th32ParentProcessID;
>      has long $.pcPriClassBase;
>      has int32 $.dwFlags;
>      HAS Str @.szExeFile[260] is CArray;# MAX_PATH on windows is 260

Did you mean to capitalize the HAS?

> };
>=20
>=20
> ... is there is a raku method that gives me the size of this data struc=
ture?
>=20
> In C for example one would use sizeof() to provide the size.=C2=A0 In r=
aku I=20
> could not find the documentation that would provide this information.
>=20
> Thanks,
> Paul Procacci

Hi Paul,

Not that I know of.  Raku has a lot of things in
the background of its structures that C does not.

C does not have OOP (object orientated programming)
but does have "struct", which is close enough.

What you are trying to do is match the C structure
of the system call with Raku's OOP "class".  In Raku,
"class" is the definition of a structure and not the
structure itself -- very much like C's "struct".

You don't get an actual structure until you
declare one from the class.  For example:

     my $x =3D PROCESSENTRY32.new;

And it is going to be a lot bigger behind the scenes
that just adding up the bits.  You really do not need
to know the behind the scene details anyway.  Raku
strives to remove the need for the programmer to
have to know these kind of details, unlike C.

What system call are you trying to run?

I have an example of how to read Windows Time
that also uses OOP (class, object, and method).
Let me know if you want it

-T



0
perl6
1/3/2021 1:39:12 AM
--000000000000a5c97e05b7f64231
Content-Type: text/plain; charset="UTF-8"

nativesizeof is what I was looking for.

Thanks,

~Paul


On Sat, Jan 2, 2021 at 8:39 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> On 1/2/21 4:58 PM, Paul Procacci wrote:
> > Hey Gents,
> >
> > Hopefully a simple question that I could not find the answer to.
> >
> > Given the following:
> >
> > class PROCESSENTRY32 is repr('CStruct') {
> >      has int32 $.dwSize;
> >      has int32 $.cntUsage;
> >      has int32 $.th32ProcessID;
> >      has Pointer $.th32DefaultHeapID;
> >      has int32 $.th32ModuleID;
> >      has int32 $.cntThreads;
> >      has int32 $.th32ParentProcessID;
> >      has long $.pcPriClassBase;
> >      has int32 $.dwFlags;
> >      HAS Str @.szExeFile[260] is CArray;# MAX_PATH on windows is 260
>
> Did you mean to capitalize the HAS?
>
> > };
> >
> >
> > ... is there is a raku method that gives me the size of this data
> structure?
> >
> > In C for example one would use sizeof() to provide the size.  In raku I
> > could not find the documentation that would provide this information.
> >
> > Thanks,
> > Paul Procacci
>
> Hi Paul,
>
> Not that I know of.  Raku has a lot of things in
> the background of its structures that C does not.
>
> C does not have OOP (object orientated programming)
> but does have "struct", which is close enough.
>
> What you are trying to do is match the C structure
> of the system call with Raku's OOP "class".  In Raku,
> "class" is the definition of a structure and not the
> structure itself -- very much like C's "struct".
>
> You don't get an actual structure until you
> declare one from the class.  For example:
>
>      my $x = PROCESSENTRY32.new;
>
> And it is going to be a lot bigger behind the scenes
> that just adding up the bits.  You really do not need
> to know the behind the scene details anyway.  Raku
> strives to remove the need for the programmer to
> have to know these kind of details, unlike C.
>
> What system call are you trying to run?
>
> I have an example of how to read Windows Time
> that also uses OOP (class, object, and method).
> Let me know if you want it
>
> -T
>
>
>
>

-- 
__________________

:(){ :|:& };:

--000000000000a5c97e05b7f64231
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">
<pre style=3D"background-color:rgb(255,255,255);color:rgb(8,8,8);font-famil=
y:&quot;JetBrains Mono&quot;,monospace;font-size:9.8pt"><span style=3D"colo=
r:rgb(0,51,179)">nativesizeof </span>is what I was looking for.<br><br></pr=
e><pre style=3D"background-color:rgb(255,255,255);color:rgb(8,8,8);font-fam=
ily:&quot;JetBrains Mono&quot;,monospace;font-size:9.8pt">Thanks,<br></pre>=
<pre style=3D"background-color:rgb(255,255,255);color:rgb(8,8,8);font-famil=
y:&quot;JetBrains Mono&quot;,monospace;font-size:9.8pt">~Paul<br></pre></di=
v><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On S=
at, Jan 2, 2021 at 8:39 PM ToddAndMargo via perl6-users &lt;<a href=3D"mail=
to:perl6-users@perl.org">perl6-users@perl.org</a>&gt; wrote:<br></div><bloc=
kquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:=
1px solid rgb(204,204,204);padding-left:1ex">On 1/2/21 4:58 PM, Paul Procac=
ci wrote:<br>
&gt; Hey Gents,<br>
&gt; <br>
&gt; Hopefully a simple question that I could not find the answer to.<br>
&gt; <br>
&gt; Given the following:<br>
&gt; <br>
&gt; class PROCESSENTRY32 is repr(&#39;CStruct&#39;) {<br>
&gt;=C2=A0 =C2=A0 =C2=A0 has int32 $.dwSize;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 has int32 $.cntUsage;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 has int32 $.th32ProcessID;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 has Pointer $.th32DefaultHeapID;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 has int32 $.th32ModuleID;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 has int32 $.cntThreads;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 has int32 $.th32ParentProcessID;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 has long $.pcPriClassBase;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 has int32 $.dwFlags;<br>
&gt;=C2=A0 =C2=A0 =C2=A0 HAS Str @.szExeFile[260] is CArray;# MAX_PATH on w=
indows is 260<br>
<br>
Did you mean to capitalize the HAS?<br>
<br>
&gt; };<br>
&gt; <br>
&gt; <br>
&gt; ... is there is a raku method that gives me the size of this data stru=
cture?<br>
&gt; <br>
&gt; In C for example one would use sizeof() to provide the size.=C2=A0 In =
raku I <br>
&gt; could not find the documentation that would provide this information.<=
br>
&gt; <br>
&gt; Thanks,<br>
&gt; Paul Procacci<br>
<br>
Hi Paul,<br>
<br>
Not that I know of.=C2=A0 Raku has a lot of things in<br>
the background of its structures that C does not.<br>
<br>
C does not have OOP (object orientated programming)<br>
but does have &quot;struct&quot;, which is close enough.<br>
<br>
What you are trying to do is match the C structure<br>
of the system call with Raku&#39;s OOP &quot;class&quot;.=C2=A0 In Raku,<br=
>
&quot;class&quot; is the definition of a structure and not the<br>
structure itself -- very much like C&#39;s &quot;struct&quot;.<br>
<br>
You don&#39;t get an actual structure until you<br>
declare one from the class.=C2=A0 For example:<br>
<br>
=C2=A0 =C2=A0 =C2=A0my $x =3D PROCESSENTRY32.new;<br>
<br>
And it is going to be a lot bigger behind the scenes<br>
that just adding up the bits.=C2=A0 You really do not need<br>
to know the behind the scene details anyway.=C2=A0 Raku<br>
strives to remove the need for the programmer to<br>
have to know these kind of details, unlike C.<br>
<br>
What system call are you trying to run?<br>
<br>
I have an example of how to read Windows Time<br>
that also uses OOP (class, object, and method).<br>
Let me know if you want it<br>
<br>
-T<br>
<br>
<br>
<br>
</blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g=
mail_signature">__________________<br><br>:(){ :|:&amp; };:</div>

--000000000000a5c97e05b7f64231--
0
pprocacci
1/3/2021 3:06:20 AM
Reply: