new/delete operators

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
ProphetOfDoom
User
User
Posts: 84
Joined: Mon Jun 30, 2008 4:36 pm
Location: UK

Post by ProphetOfDoom »

er yeah I am still quite new to PureBASIC and I didn't really expect to have to do esoteric stuff like writing a string class just to get program working properly. I wouldn't even know where to start. I did a bit of C++ once but that was about 7 years ago and I've probably forgotten most of it. And wolf thanks for trying to help but your post was a little bit... terse and I didn't get it. Anyway this is really a feature request not a workaround request (altho I am grateful for people's help).
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

since you did not explain what you used and how you programmed it,
I think it would be really difficult to read a real feature request from it...

you said you allocated memory for a selfmade "object"... fine.
you say nothing how your "object" was constructed.

if I had to guess, I would think you built a Structure for your "object".
if so, why didn't you use a LinkedList for your objects, or an Array?
as far as I know, when deleting an LL-Element containing dynamic strings,
they are deleted properly including the connected string.

if you build an "object" within some manually Allocated Memory,
you should be aware that dynamic strings in PB are not located within Structs, but only their pointers are.
when you work with pointers and memory, you have to take care of your content by yourself.
how should a FreeMemory command know, that some of the bytes contained within represent a pointer?
you have to follow that pointer first and delete the string manually,
before you Free the Memory of the "object".

as I said before, if you use LinkedLists with structured elements,
the strings from the pointers contained by those elements
should be freed correctly when deleting the elements.

another possibility to avoid this problem is, to use strings of fixed length.
those will be directly located within the structure and thus be properly deleted when freeing the memory.
oh... and have a nice day.
ProphetOfDoom
User
User
Posts: 84
Joined: Mon Jun 30, 2008 4:36 pm
Location: UK

Post by ProphetOfDoom »

Hi,

I never said that FreeMemory should magically understand that an object contains strings. That was the whole point of the topic. I suggested adding a Delete operator which *would* understand that. Like BlitzBASIC has. I couldn't use fixed strings because er, I needed unlimited length strings. I already said that. I suppose I could have used PB's own linked lists but I just decided not to.

And this:
you should be aware that dynamic strings in PB are not located within Structs, but only their pointers are.
when you work with pointers and memory, you have to take care of your content by yourself.
I know all that. I tried freeing the strings with FreeMemory but it crashes the program (judging by the post someone linked to earlier, that's because the PB strings and the other dynamic memories are in different heaps).

I think I explained pretty well how my code worked and everything. Just dynamically allocated structures with strings in. What more does anyone need to know?

I made a perfectly legitimate feature request so just/// let it be
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Post by Little John »

Hroudtwolf wrote:Why, you don't accost myself directly? ;-)
??
Hroudtwolf wrote:Its a fact, that I've expected (or interpreted) more knowledge by the threadfounder about this subject matter.
This is the reason of my "cryptic" post.
There was no basis at all for this assumption.
Hroudtwolf wrote:PS: Should I pray 100x "Our Father..." for my bad mistake?
I would be sufficient not to "accost" other people because of your mistake.

ProphetOfDoom wrote:er yeah I am still quite new to PureBASIC and I didn't really expect to have to do esoteric stuff like writing a string class just to get program working properly.
I hope in the meantime it has become clear that you don't have to do so, of course!
ProphetOfDoom wrote:I made a perfectly legitimate feature request so just/// let it be
I agree.

Regards, Little John
ProphetOfDoom
User
User
Posts: 84
Joined: Mon Jun 30, 2008 4:36 pm
Location: UK

Post by ProphetOfDoom »

:D
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Little John wrote:There was no basis at all for this assumption.
To ascertain this, should be outside your province. ;-)
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Post by Little John »

You don't know anything about my province.

Regards, Little John
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

^____^
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

I think I explained pretty well how my code worked and everything. Just dynamically allocated structures with strings in. What more does anyone need to know?
"dynamically allocated structures" was what I guessed, there not a single word explaining it in yout first post.
I know all that.
then you should be able to write your own object destructor.
ProphetOfDoom wrote:I made a perfectly legitimate feature request
I don't think so.

you are not only asking for a kill routine, you are asking for a completely new object handling system.


but awright, we are spamming a feature-request-thread.
some Mod should delete the crap and you should wait for an answer from the team...
oh... and have a nice day.
Post Reply