Adress Change

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
AndyX
User
User
Posts: 12
Joined: Wed May 04, 2005 6:40 pm
Location: Austria

Adress Change

Post by AndyX »

Will there be a feature in a future version of PB to allow changing the adress of a array,var,...?

Like that in C:

Code: Select all

(int *)var = &other_var;
edit: Please don´t throw stones at me if that is a stupid idea! :D
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Re: Adress Change

Post by Joakim Christiansen »

AndyX wrote:PB 43.93 ROCKZ!!!
OMG, where did you get that version? :shock: :shock:
I like logic, hence I dislike humans but love computers.
AndyX
User
User
Posts: 12
Joined: Wed May 04, 2005 6:40 pm
Location: Austria

Post by AndyX »

Stolen it from Freds safe :twisted:

:P
AndyX
User
User
Posts: 12
Joined: Wed May 04, 2005 6:40 pm
Location: Austria

Re: Adress Change

Post by AndyX »

AndyX wrote:Will there be a feature in a future version of PB to allow changing the adress of a array,var,...?

Like that in C:

Code: Select all

(int *)var = &other_var;
edit: Please don´t throw stones at me if that is a stupid idea! :D
Is it a stupid idea?
SCRJ
User
User
Posts: 93
Joined: Sun Jan 15, 2006 1:36 pm

Post by SCRJ »

>>Is it a stupid idea?
Yes :lol:

I think that would be a nice feature...
AndyX
User
User
Posts: 12
Joined: Wed May 04, 2005 6:40 pm
Location: Austria

Post by AndyX »

It would really be a nice feature when handling large datas.

for example:
I have a 4x4 matrix that i want to clear out.
I would have to do 16 lines of

Code: Select all

matrix\m00 = 0
matrix\m01 = 0
....
Instead of this i could create a nullmatrix and easily set the adress of the matrix to the nullmatrix:

Code: Select all

(long *)matrix = @Nullmatrix
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Or you could simply do this:

Code: Select all

For x=0 To 3
  For y=0 To 3
    Array(x,y) = 0
  Next
Next
Or just dim it again:

Code: Select all

Dim Array(3,3)

For x=0 To 3
  For y=0 To 3
    Array(x,y) = 1
  Next
Next

Dim Array(3,3)

For x=0 To 3
  For y=0 To 3
    Debug Array(x,y)
  Next
Next

;This is how to delete the content of an array and release its used memory
Dim Array(0)
I like logic, hence I dislike humans but love computers.
AndyX
User
User
Posts: 12
Joined: Wed May 04, 2005 6:40 pm
Location: Austria

Post by AndyX »

But what if its not an array?

What about this:

Code: Select all

Structure OBJECT4DV1
  id.l
  name.s
  state.l
  attr.l
  avg_radius.f
  max_radius.f
  world_pos.POINT4D
  dir.VECTOR4D
  ux.VECTOR4D
  uy.VECTOR4D
  uz.VECTOR4D
  num_vertices.l
  vlist_local.POINT4D[#OBJECT4DV1_MAX_VERTICES]
  vlist_trans.POINT4D[#OBJECT4DV1_MAX_VERTICES]
  num_polys.l
  plist.POLY4DV1[#OBJECT4DV1_MAX_POLYS]
EndStructure

obj.OBJECT4DV1
Setting this to null eats lots of lines. edit/: and lots of time.

Well, if its so stupid, please some member of the Purebasic team come here and close this thread :)

edit: sorry if i´m annoying you ^^
User avatar
IceSoft
Addict
Addict
Posts: 1682
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Post by IceSoft »

Is this your feature request?

Code: Select all

a.l = 5
*aPtr.l = @a
Debug PeekL(*aPtr)

b .l = 10
*aPtr = @b
Debug PeekL(*aPtr)
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
AndyX
User
User
Posts: 12
Joined: Wed May 04, 2005 6:40 pm
Location: Austria

Post by AndyX »

yes, it is.

But without having to use the PeekX()/PokeX() commands to get the value.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

or maybe, in particular case, you can use the 'swap a, b' keyword.

it works for vars, arrays and elements of linked-lists.

Code: Select all

Dim a.l(10)
Dim b.l(10)

For i = 0 To 9
  b(i) = 100 + i
Next

Swap a(), b()

For i = 0 To 9
  Debug a(i) 
Next
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

AndyX wrote:yes, it is.

But without having to use the PeekX()/PokeX() commands to get the value.

Code: Select all

a.l = 5 
*aPtr.Long = @a 
Debug *aPtr\l

b .l = 10 
*aPtr.Long = @b 
Debug *aPtr\l
:?:
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
AndyX
User
User
Posts: 12
Joined: Wed May 04, 2005 6:40 pm
Location: Austria

Post by AndyX »

Flype wrote:or maybe, in particular case, you can use the 'swap a, b' keyword.

it works for vars, arrays and elements of linked-lists.

Code: Select all

Dim a.l(10)
Dim b.l(10)

For i = 0 To 9
  b(i) = 100 + i
Next

Swap a(), b()

For i = 0 To 9
  Debug a(i) 
Next
With Swap and large amount of datas you won´t know where what is after the time...
AndyX wrote:
yes, it is.

But without having to use the PeekX()/PokeX() commands to get the value.


Code:
a.l = 5
*aPtr.Long = @a
Debug *aPtr\l

b .l = 10
*aPtr.Long = @b
Debug *aPtr\l


Question
hm... but then i have to declare all things with * and .LONG, hmmmm..
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

AndyX wrote:But what if its not an array?

What about this:

Code: Select all

Structure OBJECT4DV1
  id.l
  name.s
  state.l
  attr.l
  avg_radius.f
  max_radius.f
  world_pos.POINT4D
  dir.VECTOR4D
  ux.VECTOR4D
  uy.VECTOR4D
  uz.VECTOR4D
  num_vertices.l
  vlist_local.POINT4D[#OBJECT4DV1_MAX_VERTICES]
  vlist_trans.POINT4D[#OBJECT4DV1_MAX_VERTICES]
  num_polys.l
  plist.POLY4DV1[#OBJECT4DV1_MAX_POLYS]
EndStructure

obj.OBJECT4DV1
Setting this to null eats lots of lines. edit/: and lots of time.

Well, if its so stupid, please some member of the Purebasic team come here and close this thread :)

edit: sorry if i´m annoying you ^^
Remember it is initialized to 0 when you create it. And you can use this line to zero out the entire structure:

Code: Select all

RtlZeroMemory_(@obj, SizeOf(obj))
Post Reply