Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

possible to permanently cast to parent? (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: Rnadom Numbers..
Next thread: Re: How to prevent 'proportionlal spacing' in listboxes


Win32 API Declares   -   Berg, Heath
  possible to permanently cast to parent?   -   Mike Woodworth
   Re: possible to permanently cast to parent?   -   Joseph J. Strout
   Re: possible to permanently cast to parent?   -   Mark Nutter

possible to permanently cast to parent?
Date: 01.08.05 17:36 (Mon, 1 Aug 2005 11:36:49 -0500)
From: Mike Woodworth
this is a strange one...

i'm writing a socket class which accepts dictionaries and sends them
to another copy of the app on another machine. the socket handles
the serializing of all intrinsic datatypes in rb and objects such as
memoryblocks. it also accepts custom classes that implement a
serializeable interface - which has one method serialize. it is up
to the class to flatten itself to a dictionary filled with only
standard datatypes. this works very well... saves overhead so i only
have to convert stuff like memoryblocks to strings once in the actual
writing to socket stage - there's just one hangup in my app.

i have a class picblock which is a subclass of memoryblock. the
subclass implements serializable. so when passed into my
socketclass, it calls the picblock.serialize method:

Function serialize() As dictionary
dim dict as new Dictionary

dict.Value("width") = w
dict.Value("height") = h
dict.Value("data") = MemoryBlock(me)

return dict
End Function

problem is... the value in key "data" is still treated as a picblock,
so when the socket tries to flatten this dict it finds the picblock
and calls serialize again and again and again... stack overflow.

my question is, without resorting to any data copying or slow junk
(these memoryblocks are 300k and im trying to pass lots o them
quickly) is there any way to cast the picblock as a memoryblock such
that it can go into a variant and variant.objectvalue isa picblock =
false? ie it is only a memoryblock now?

mike

Re: possible to permanently cast to parent?
Date: 01.08.05 17:53 (Mon, 1 Aug 2005 10:53:55 -0600)
From: Joseph J. Strout
At 11:36 AM -0500 8/1/05, Mike Woodworth wrote:

>i have a class picblock which is a subclass of memoryblock. the
>subclass implements serializable. so when passed into my
>socketclass, it calls the picblock.serialize method:
>
>Function serialize() As dictionary
> dim dict as new Dictionary
>
> dict.Value("width") = w
> dict.Value("height") = h
> dict.Value("data") = MemoryBlock(me)
>
> return dict
>End Function
>
>problem is... the value in key "data" is still treated as a picblock

(and indeed, it IS still a picblock)

>so when the socket tries to flatten this dict it finds the picblock
>and calls serialize again and again and again... stack overflow.

Right. You need a different design here; an object can't include a
reference to itself as part of serializing itself.

>my question is, without resorting to any data copying or slow junk
>(these memoryblocks are 300k and im trying to pass lots o them
>quickly) is there any way to cast the picblock as a memoryblock such
>that it can go into a variant and variant.objectvalue isa picblock =
>false? ie it is only a memoryblock now?

No, an object is what it is, from creation to destruction. This
particular object is a picblock, so no matter how you refer to it, it
always IsA picblock. You could make *another* object which is not a
picblock, but happens to contain the same data, but that's what
you're trying to avoid.

The simplest solution would be to stuff the StringValue of the data
into the dictionary, instead of a reference to self. This does
probably mean one extra copy, but you may find in practice that this
is not a bottleneck.

HTH,
- Joe

Re: possible to permanently cast to parent?
Date: 01.08.05 17:59 (Mon, 1 Aug 2005 09:59:07 -0700 (PDT))
From: Mark Nutter


--- Mike Woodworth <<email address removed>> wrote:

> i have a class picblock which is a subclass of
> memoryblock. the
> subclass implements serializable. so when passed
> into my
> socketclass, it calls the picblock.serialize method:
>
> Function serialize() As dictionary
> dim dict as new Dictionary
>
> dict.Value("width") = w
> dict.Value("height") = h
> dict.Value("data") = MemoryBlock(me)
>
> return dict
> End Function
>
> problem is... the value in key "data" is still
> treated as a picblock,
> so when the socket tries to flatten this dict it
> finds the picblock
> and calls serialize again and again and again...
> stack overflow.

You can't permanently cast your picblock to a memory
block, but how about if you add a boolean function
called Serialized to your Serializable interface?
That would let you set a flag in your picblock that
you could check for when you go to serialize it, so
that you don't have infinite recursion. Have a
Serialized(Assigns flag As Boolean) to go with it so
you can set the flag in your call to Serialize.

Probably overkill for some (most?) of your other data
structures, but that's all I can think of at the
moment. Maybe it'll suggest other ideas?

Mark Nutter

Quick and easy regex creation and debugging!
http://www.bucktailsoftware.com/products/regexplorer/


____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>