SizeOf( Array() ) ?

Everything else that doesn't fall into one of the other PB categories.
The_CodeMaster
User
User
Posts: 41
Joined: Wed Dec 29, 2004 11:39 am
Location: Belgium

Post by The_CodeMaster »

Than i can't convert this Source from Powerbasic to Purebasic.
euhm, if you have an array in PowerBasic from ex. (30 to 90) then just convert it to (0 to 60) or just 'dim variable(60)'. You'll have to make sure that the starting-index is 0 and in this case you'll have to substract 30 to get THAT 0.

So it's possible to convert, but proberly a lot of work :? .

Tried to read your german post, but don't understand German.
User avatar
Falko
Enthusiast
Enthusiast
Posts: 271
Joined: Sat Oct 04, 2003 12:57 pm
Location: Germany
Contact:

Post by Falko »

Thanks for your tip. I will see to convert the Powerbasic Code to Purebasic.
I hope this do funtionary in Purebasic to write an XLS-Sheet.

Sorry, but i can't translate all german Thread with my little english.

Best regards from germany
Falko
www.falko-pure.de
Win11 Pro 64-Bit, PB_6.11b1
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

freak wrote:

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
Hey guys, have you seen that?
That's the Power of PureBasic :twisted:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Code: Select all

Procedure.l ArrayMemorySize(*Array) 
  !sub [p.p_Array], dword 8 
  !push dword [p.p_Array] 
  !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) 
array(8)=45

Debug ArrayMemorySize(@Array()) 
Debug ArraySize(@Array())
ArrayMemorySize() doesn't work in PB 4.02

And 2nd: what about SizeOf(linkedlist()) :?:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

This code gives me the size of the array +1. Is it safe to assume that in PB4 the correct value is PeekL(*Array-8)-1?

Code: Select all

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

Dim Array.l(50)

Debug ArraySize(@Array())
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

There is no problem:

Dim x(3)

=

x(0) 1 element
x(1) 2 elements
x(2) 3 elements
x(3) 4 elements

In an array dimed like that "Dim x(50)", there's fifty one elements :D
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

in other words, it does not give you the size of the array +1,
but precisely the size of the Array.

remember, in PB you Dim an Array withe the index of the last element,
not with the numer of elements, and an array always starts at index 0.

so, with Dim x(50) you Dim 51 elements as Olli said.

if you want 50 Elements, you'll need index 0-49, then use Dim x(49)

...this is different to other BASIC languages, but it's a known issue in PB.
oh... and have a nice day.
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

Updated

Code: Select all

Procedure.l ArrayMemorySize(*Array) 
  !sub [p.p_Array], dword 20
  !push dword [p.p_Array] 
  !push dword 0 
  !push dword [PB_MemoryBase] 
  !call _HeapSize@12 
  ProcedureReturn 
  HeapSize_(0, 0, 0) ; make sure, _HeapSize@12 is defined 
EndProcedure 
Ollivier
Enthusiast
Enthusiast
Posts: 281
Joined: Mon Jul 23, 2007 8:30 pm
Location: FR

Post by Ollivier »

Image :o
:D
Post Reply