New topic: Huge delay when passing byval properties to events
<http://forums.realsoftware.com/viewtopic.php?t=45588> Page 1 of 1 [ 3 posts ] Previous topic | Next topic Author Message sbeach Post subject: Huge delay when passing byval properties to eventsPosted: Thu Oct 11, 2012 11:14 pm Joined: Wed May 10, 2006 1:27 pm Posts: 66 Sorry, for the vague-ish title, not sure how to eloquently describe my entire problem. I have a UDP socket that is receiving datagrams (about 550 bytes each) very rapidly (at least 44 times per second). As this is an extension of an existing protocol, I'm sort of married to the rules of the protocol. Nevertheless 44hz should be plenty of time to do what I'm doing, but I'm encountering something I've never experienced before (or never noticed). The protocol supports over a dozen different types of packets, so to keep everything clean and sexy I subclassed a UDP socket. In the DataAvailable event I immediately convert the data into a MemoryBlock, read the header (about 12 bytes) and then manage each type of packet in a select/end select block. This involves pulling anywhere from 5 to 10 integer values out of the memory block, taking the rest of the packet and converting it to a second memory block *just* for the payload, and passing all the above as arguments to a custom event for each type of packet. So I could have something like SomeNumber1 = myMemoryBlock.int8Value(12) SomeNumber2 = myMemoryBlock.int8Value(13) SomeNumber3 = myMemoryBlock.int8Value(14) PayloadLength = myMemoryBlock.int16Value(15) dim Payload as MemoryBlock = myMemoryBlock.stringValue(17,PayloadLength) CustomEvent(SomeNumber1,SomeNumber2,SomeNumber3,PayloadLength,Payload) What I find unusual and would love some insight into, is the following behavior: If I send literals and no memory block to my CustomEvent: CustomEvent(0,0,0,0,nil) It will fire say every 2000 microseconds. If I send literals and my memory block to my CustomEvent: CustomEvent(0,0,0,0,nil) It will fire say every 2500 microseconds. Negligible, perhaps because I'm sending an object by reference, not value. But as soon as I send ANY of my other values: CustomEvent(SomeNumber1,SomeNumber2,SomeNumber3,PayloadLength,Payload) 'Or even just: CustomEvent(SomeNumber1,0,0,0,Payload) It will bog down, the buffer will back up, and the event will only fire every 500,000 microseconds. A whole half second seems ridiculous. What on earth am I missing? I've tried skipping the variable assignment and just calling the MemoryBlock.int8Value as the arguments I've created private properties as part of my object to hold the data so I wasn't allocating/destroying memory each time my DataAvailable event fired. I've tried changing the type of the parameter from uInt8 to regular old Integers, same goes for the properties. I'm at a loss. I ran out of time to try passing the values by reference, but I'll try that first thing tomorrow. If that doesn't work do I need to create a custom object for each type of packet that carries the packet information? If that doesn't work, where am I left? Can anyone provide some insight as to why I'm experiencing this behavior? _________________ -Sean Top timhare Post subject: Re: Huge delay when passing byval properties to eventsPosted: Thu Oct 11, 2012 11:37 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 11722 Location: Portland, OR USA How are SomeNumber1, etc., defined? How are the parameters of CustomEvent defined? There is something real screwy going on. And do you have more than one event with the same name and different parameters? Top sbeach Post subject: Re: Huge delay when passing byval properties to eventsPosted: Thu Oct 11, 2012 11:50 pm Joined: Wed May 10, 2006 1:27 pm Posts: 66 timhare wrote:How are SomeNumber1, etc., defined? How are the parameters of CustomEvent defined? There is something real screwy going on. Presently they're defined as private properties of the class SomeNumber1 as Integer I've also tried defining them locally: Dim SomeNumber1 as Integer I've tried both options with them as uInt8 or uInt16 types as well. The parameters of CustomEvent are also Integers right now, but I've tried them as uInt8 and uInt16 as well. I've never had the values recast as a different type (uInt8 to integer or integer to uInt8) while passing the parameter. timhare wrote:And do you have more than one event with the same name and different parameters? Nope. _________________ -Sean Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 3 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
