It is currently Thu Sep 09, 2010 8:39 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [Done] map of pointers to structured list elements
PostPosted: Fri Jul 16, 2010 5:07 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Jun 28, 2003 12:01 am
Posts: 249
Hello,

Here the example:
Code:
EnableExplicit

Structure tJOB
   JobID.i
   JobKey.s
   *Parent.tJOB_CATEGORY
   DataType.i
   DataSize.i
   *JobData
EndStructure

Structure tJOB_CATEGORY
   CategoryName.s
   List Jobs.tJOB()
EndStructure

Global NewMap JobCategories.tJOB_CATEGORY()
Global NewMap *Jobs.tJOB()

Procedure AddJob( Category.s, JobData )
   Static    JobID
   Protected JobKey.s
   Protected *Category.tJOB_CATEGORY, *NewJob.tJOB
   
   *Category = FindMapElement( JobCategories(), Category )
   If Not *Category
      *Category = AddMapElement( JobCategories(), Category )
      *Category\CategoryName = Category
   EndIf
   
   Repeat
      JobID + 1
      JobKey = Str(JobID)
   Until Not FindMapElement( *Jobs(), JobKey )
   
   *NewJob = AddElement( *Category\Jobs() )
   *Jobs( JobKey )  = *NewJob
   
;   With *NewJob
;   With *Category\Jobs()
   With *Jobs( JobKey )
      \JobID = JobID
      \JobKey = JobKey
      \JobData = JobData
      \Parent  = *Category
   EndWith
   
   ProcedureReturn JobID
EndProcedure

AddJob( "IDLE", Random( $FFFF ) )
AddJob( "DEFAULT", Random( $FFFF ) )
AddJob( "IDLE", Random( $FFFF ) )
AddJob( "HIGH", Random( $FFFF ) )
AddJob( "HIGH", Random( $FFFF ) )
AddJob( "HIGH", Random( $FFFF ) )
AddJob( "IDLE", Random( $FFFF ) )
AddJob( "DEFAULT", Random( $FFFF ) )
AddJob( "HIGH", Random( $FFFF ) )
AddJob( "HIGH", Random( $FFFF ) )
AddJob( "HIGH", Random( $FFFF ) )
AddJob( "IDLE", Random( $FFFF ) )
AddJob( "DEFAULT", Random( $FFFF ) )


Debug LSet("",100,"-")
Debug "Access to jobs over the lists in the category structure."
Debug "The categories are maintained in a map JobCategories()."
ResetMap( JobCategories() )
While NextMapElement( JobCategories() )
   With JobCategories()
      Debug Str(ListSize(\Jobs())) + " jobs in category " + JobCategories()\CategoryName
      ForEach \Jobs()
         Debug "    Job " + Str(\Jobs()\JobID) + " // JobData = " + Str(\Jobs()\JobData) + " // cateogory = " + \Jobs()\Parent\CategoryName
      Next
   EndWith
Wend

Debug ""
Debug LSet("",100,"-")
Debug "Access to the list items over the pointers,"
Debug "which are stored in the map *Jobs()"
Debug "Access to single items is possible using the JobID!"
ResetMap( *Jobs() )
While NextMapElement( *Jobs() )
   With *Jobs()
      Debug "-"
      Debug "MapKey = " + MapKey(*Jobs())
      Debug "JobKey = " + \JobKey
      
      ; ==> VERY STRANGE: only empty lines are print to the debug window!
      Debug "JobID  = " + Str(\JobID)
      Debug "Data   = " + Str(\JobData)
      Debug "Parent = " + Str(\Parent)
   EndWith
Wend

The single items of the list in the structure tJOB_CATEGORY contain job information. The size of one list element is SizeOf(tJOB).

In the example a pointer of each job element (independent of the category) is stored in the Map *Jobs.tJob(). The single elements in this map however have the size of an pointer (Integer) and not the size SizeOf(tJOB). This is a map of pointers to tJOB items.

Sadly there seems to be a bug, if you access the single job items over the map. You will get the wrong data even though inside the procedure AddJob the data is set using the map pointer.

Is the use of "Map *Job.tSTRUCTURE_NAME()" allowed to create a map of pointers to structured list elements?

cu, guido

_________________
Laptop Fujitsu-Siemens Amilo PRO V2065
Intel Pentium M 1.86 GHz / 1 GByte Ram
PureBasic Last Final and Beta


Top
 Profile  
 
 Post subject: Re: map of pointers to structured list elements
PostPosted: Fri Jul 16, 2010 5:19 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Jan 10, 2008 1:30 pm
Posts: 131
Location: Germany, Glienicke
smaler code with the bug:
Code:
Global NewMap *Punkt.Point()

Punkt.Point\x = 123
Punkt.Point\y = 456

*Punkt("Test") = @Punkt

Debug *Punkt("Test")\x
Debug *Punkt("Test")\y

Debug "---"

ForEach *Punkt()
  Debug *Punkt()\x
  Debug *Punkt()\y
Next


Code:
Global NewMap *Punkt.Point()

Punkt.Point\x = 123
*Punkt("Test") = @Punkt

ForEach  *Punkt()
  Debug Str(*Punkt()\x)
Next

_________________
Image


Top
 Profile  
 
 Post subject: Re: map of pointers to structured list elements
PostPosted: Fri Jul 16, 2010 5:41 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Jun 28, 2003 12:01 am
Posts: 249
Thank you STARGÅTE,

for you help :-)

_________________
Laptop Fujitsu-Siemens Amilo PRO V2065
Intel Pentium M 1.86 GHz / 1 GByte Ram
PureBasic Last Final and Beta


Top
 Profile  
 
 Post subject: Re: map of pointers to structured list elements
PostPosted: Tue Jul 20, 2010 6:42 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 6298
Location: France
Fixed.


Top
 Profile  
 
 Post subject: Re: [Done] map of pointers to structured list elements
PostPosted: Thu Jul 22, 2010 9:13 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Jan 10, 2008 1:30 pm
Posts: 131
Location: Germany, Glienicke
Bug isn't fixed :

The problem with the Str() or other functions is not fixed
Code:
Global NewMap *Punkt.Point()

Punkt.Point\x = 123
*Punkt("Test") = @Punkt

ForEach  *Punkt()
  Debug Str(*Punkt()\x) ; <-- here!
Next

_________________
Image


Top
 Profile  
 
 Post subject: Re: map of pointers to structured list elements
PostPosted: Thu Jul 22, 2010 7:25 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 213
Location: Germany
Confirm with x86. With x64 it´s ok
Code:
Global NewMap *Punkt.Point()

Punkt.Point\x = 123
*Punkt("Test") = @Punkt

ForEach  *Punkt()
  x.s = Str(*Punkt()\x) ; IMA here
  Debug x
Next

_________________
Sorry, My english is not so good


Top
 Profile  
 
 Post subject: Re: map of pointers to structured list elements
PostPosted: Mon Aug 16, 2010 8:43 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 6298
Location: France
Fixed.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Google Adsense [Bot], Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye