SizeOf( Array() ) ?

Everything else that doesn't fall into one of the other PB categories.
Codemonger
Enthusiast
Enthusiast
Posts: 384
Joined: Sat May 24, 2003 8:02 pm
Location: Canada
Contact:

SizeOf( Array() ) ?

Post by Codemonger »

Does anybody know how to get the sizeof() an array.... not the upper or lower bounds of the elements but the actually length in bytes of the whole array ... or at least the length in bytes of one array ?
<br>"I deliver Justice, not Mercy"

    - Codemonger, 2004 A.D.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Code: Select all

Procedure.l ArrayMemorySize(*Array)
  !sub [esp], dword 8
  !push dword [esp]
  !push dword 0
  !push dword [PB_MemoryBase]
  !call _HeapSize@12
  ProcedureReturn
  HeapSize_(0, 0, 0) ; make sure, _HeapSize@12 is defined
EndProcedure

Procedure ArraySize(*Array)
  ProcedureReturn PeekL(*Array-8)
EndProcedure


Dim Array.l(50)


Debug ArrayMemorySize(@Array())
Debug ArraySize(@Array())
ArrayMemorySize() shows the real size in memory.
ArraySize() shows the total number of elements.

Timo
quidquid Latine dictum sit altum videtur
Codemonger
Enthusiast
Enthusiast
Posts: 384
Joined: Sat May 24, 2003 8:02 pm
Location: Canada
Contact:

Post by Codemonger »

Thanks Freak your a lifesaver ...
<br>"I deliver Justice, not Mercy"

    - Codemonger, 2004 A.D.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

How secure is this for future versions of PB.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

> How secure is this for future versions of PB.

Do you know of much other ways to allocate an Array than HeapAloc ??
If something changes, what's the deal of changing this procedure, too ?

Timo
quidquid Latine dictum sit altum videtur
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

freak wrote: Procedure.l ArrayMemorySize(*Array)
!sub [esp], dword 8
!push dword [esp]
!push dword 0
!push dword [PB_MemoryBase]
!call _HeapSize@12
ProcedureReturn
HeapSize_(0, 0, 0) ; make sure, _HeapSize@12 is defined
EndProcedure
Freak I have a question for you:

HeapSize_(0, 0, 0) ; make sure, _HeapSize@12 is defined

comes after:

ProcedureReturn

and I thought ProcedureReturn is like a break because it exits the Procedure right away.
So:

HeapSize_(0, 0, 0) ; make sure, _HeapSize@12 is defined

will never be executed... or am I wrong :?:

I am to provide the public with beneficial shocks.
Alfred Hitshock
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Freak I have a question for you:

HeapSize_(0, 0, 0) ; make sure, _HeapSize@12 is defined

comes after:

ProcedureReturn

and I thought ProcedureReturn is like a break because it exits the Procedure right away.
So:

HeapSize_(0, 0, 0) ; make sure, _HeapSize@12 is defined

will never be executed... or am I wrong
Yes, you are right, and calling HeapSize with a lot of 0's would definately
fail.

I call the HeapSize directly from asm, ans since it is external, it has to
be defined with

!extrn _HeapSize@12

in order to be used. The problem is, as soon as somebody uses
HeapSize_(), PB will automatically define the symbol, and you get an
'allready defined' error. So, to prevent that, i just insert HeapSize_() at
some point, where it will never be executed, just so that PB defines the
symbol for me.

Dirty little trick, i know, but... :wink:

Timo
quidquid Latine dictum sit altum videtur
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

very handy for the a new UBOUND(Array) Command:

Code: Select all

Dim MYArray.b(4711)

Procedure Ubound(*Array)
 ProcedureReturn PeekL(*Array-8)
endprocedure

Debug Str(UBound(@MyArray(0)))
SPAMINATOR NR.1
User avatar
Falko
Enthusiast
Enthusiast
Posts: 271
Joined: Sat Oct 04, 2003 12:57 pm
Location: Germany
Contact:

Post by Falko »

Hi @freak

And have you a code to make 'Lbound'?

Thanks Falko
www.falko-pure.de
Win11 Pro 64-Bit, PB_6.11b1
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

Procedure LBound(*Array)
procedurereturn 0
endprocedure
SPAMINATOR NR.1
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Post by helpy »

Rings wrote:Procedure LBound(*Array)
procedurereturn 0
endprocedure
:P :lol:
User avatar
Falko
Enthusiast
Enthusiast
Posts: 271
Joined: Sat Oct 04, 2003 12:57 pm
Location: Germany
Contact:

Post by Falko »

thanks @Rings, but this Source have many errors. It does not rearly help.
Here the german link.

http://robsite.de/php/pureboard/viewtopic.php?t=1318

Can any help me please to corecting this source?

Sorry, my english from german post,

Falko
www.falko-pure.de
Win11 Pro 64-Bit, PB_6.11b1
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Post by helpy »

Falko wrote:thanks @Rings, but this Source have many errors. It does not rearly help.
Here the german link.

http://robsite.de/php/pureboard/viewtopic.php?t=1318

Can any help me please to corecting this source?

Sorry, my english from german post,

Falko
------GERAMAN---------------
Hi Falko,

LBound in PureBasic ist IMMER 0 !!!

In anderen Sprachen ist es möglich ein Array zu definieren, das von 50 bis 100 geht, wobei LBOUND in diesem Fall 50 ist. Würde man einen Index außerhalb dem Bereich [50-100] aufrufen würde es eine Fehlermeldung geben.

------ENGLISH---------------
LBound in PureBasic is ALWAYS 0 !!!

In otzer programming languages it is possible to define arrays (i.e.) from 50 to 100. In this case LBOUND would return 50. If you would try to get an index outside the range [50-100] an error would occur.

cu, helpy
User avatar
Falko
Enthusiast
Enthusiast
Posts: 271
Joined: Sat Oct 04, 2003 12:57 pm
Location: Germany
Contact:

Post by Falko »

Thanks @helpy
Than i can't convert this Source from Powerbasic to Purebasic.
:roll:

It's very usefull to make a own Excel-Sheet over Purebasic. :)

Falko
www.falko-pure.de
Win11 Pro 64-Bit, PB_6.11b1
User avatar
helpy
Enthusiast
Enthusiast
Posts: 552
Joined: Sat Jun 28, 2003 12:01 am

Post by helpy »

Falko wrote:Thanks @helpy
Than i can't convert this Source from Powerbasic to Purebasic.
:roll:
Why not? As I can see, in the original code there are only zero based arrays used. So ... instead of LBound(...) you can insert the value "0" (zero).

cu, helpy
Post Reply