why is my pointer not being recognized in the struct?

Just starting out? Need help? Post your questions and find answers here.
jorgejones
User
User
Posts: 32
Joined: Tue Mar 21, 2006 8:27 am

Post by jorgejones »

thanks { i will read that last post twice or more to fully understand it }

so far i got a question:: could this be adapted to my multi-structure case using my peek/poke idea?

i just can not test in here because anything i do returns fine which i think is not correct

why is this happening in this pc? why it never complains about the memory?

thanks

oh did you see my last post or we posted at same times?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I did see it after I posted, but you know, one thing at a time! :)

Personally, I haven't looked too closely at your Peeks and Pokes because I generally avoid such statements in favour of... pointers! :wink:
I may look like a mule, but I'm not a complete ass.
jorgejones
User
User
Posts: 32
Joined: Tue Mar 21, 2006 8:27 am

Post by jorgejones »

if i could manage linked lists in a nice way and also access their data without having to call functions perhaps i should try those instead ?

i just wanted this to work :cry:
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

In my experience there is very little you cannot achieve with this kind of approach. You just need to lay your requirements out very carefully; treat pointers with a little respect ( :wink: ), and do not go overboard with them!

I spend most of my time creating Windows controls now and for that, I will not use a linked list because of the need to protect them when creating multi-threaded applications. Instead I go for dynamic memory allocations which I usually map to a structure (by using a simple pointer as already demonstrated). Believe me, some of the data I deal with is very complex, but nothing that can't be handled by PB with methods based on structures, pointers and the memory commands.

I think you just need to slow down a little perhaps and study the basics of PB' structures, pointers and memory commands. They are very simple once you've gotten to grips with them. :)

**EDIT : btw, you can access linked list elements without commands. A linked list element is just a structure and can be accessed by pointers without any trouble.
I may look like a mule, but I'm not a complete ass.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
jorgejones
User
User
Posts: 32
Joined: Tue Mar 21, 2006 8:27 am

Post by jorgejones »

srod: i will read more i just cant test if it keeps on smiling on me while things could be wrong do you know why is this happening?

psychophanta: thanks but i still have the problem with multiple structs with dynamic elements!

:?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

To deal with structs and pointers is not an easy task, over all if you work with multiple strucs and linked lists, etc... And that requires a lot of care and attention in order to make well done things.
However don't worry, read and test a little more as srod says and if after that you continue with problems, then return back with it. :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
jorgejones
User
User
Posts: 32
Joined: Tue Mar 21, 2006 8:27 am

Post by jorgejones »

thanks i will

about the memory issue how do i get rid of that? it wont raise an error even if i allocate just 1 byte :?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Which memory issue?
I may look like a mule, but I'm not a complete ass.
jorgejones
User
User
Posts: 32
Joined: Tue Mar 21, 2006 8:27 am

Post by jorgejones »

the fact that whether i allocate it or not it always returns just fine instead of giving me an error :?
jorgejones
User
User
Posts: 32
Joined: Tue Mar 21, 2006 8:27 am

Post by jorgejones »

i dont know why but when i use the debugger i almost get no memory errors with this sort of code :?

on a side note:: is it possible to define a linkedlist inside another?

something like this i mean

Code: Select all

NewList childs.child()
NewList childs()\offsprings.offspring()
:?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

No. :)
I may look like a mule, but I'm not a complete ass.
jorgejones
User
User
Posts: 32
Joined: Tue Mar 21, 2006 8:27 am

Post by jorgejones »

so im still doomed about this :lol:
and for the first time im beginning to feel frustrated about it

to put it in a simpler context say id wanted to make particles with emitters or have xml nodes with childs or something like this how can i manage it in a transparent way { a way that could let me dynamically do whatever i want } ?

Code: Select all

parent
 |
 |-> child
 |      |-> object
 |      |-> object
 |      |-> object
 |      |-> (etc)...
 |
 |-> child
 |      |-> object
 |      |-> object
 |      |-> object
 |      |-> (etc)...
 |
im after something elegant yet fast because i would like to simulate quite a few laws of physics with this so i cant be calculating pointer displacements all the time although i would do it happily if thats the solution and its the only one available at the time

i just wished i could get reliable error messages to begin with


edit: i guess it is fine to think about the stars as particles anyway at least in this case
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Are you after a tree data structure?
I may look like a mule, but I'm not a complete ass.
jorgejones
User
User
Posts: 32
Joined: Tue Mar 21, 2006 8:27 am

Post by jorgejones »

well as i mentioned i have a parent then objects and inside those objects i have more objects

the tree i described pretty much is what im after

yet i would like to make more than an universe and each should be independent

the main purpose is to later on test a few theories i have about wormholes but all this pointer stuff is setting me back big time

anyway its nothing ''out of this world'' i just need to comprehend the existent theories and try out my own

with a simple and inaccurate system i wont go far but at least ill have somewhere to start from plus i wont be simulating entire galaxies
Post Reply