[DUG] Reference counting

Ross Levis ross at stationplaylist.com
Thu Nov 24 23:19:03 NZDT 2005


myOffice Email MessageI use a Memory Sharing component called fisSharedMemory which works very well.  You can specify a memory block size and use short strings (up to 255 chars).  I'm using it with a Record structure with many different variables.

I use one variable in the record which is being polled in a Timer to test if new values have been updated by the other application.  The variable is then reset after being read.  It works very well and very fast.

http://sodev.webzdarma.cz/show.php?page=Others&la=en&kateg=Systems
(very slow website, but some very interesting componets)

Regards,
Ross.
  ----- Original Message ----- 
  From: Gary T. Benner 
  To: kyleyharris at gmail.com 
  Cc: delphi at ns3.123.co.nz 
  Sent: Thursday, November 24, 2005 10:29 PM
  Subject: RE: Re: [DUG] Reference counting


  [Reply] 
  Hi all, 

  To "send a string" using windows messaging, use Global Atoms, and send the reference to the Atom in the Windows Message. 

  Look at: 

  http://www.delphipages.com/threads/thread.cfm?ID=24029&G=24027 

  cheers 

  Gary 

  At 19:43 on 24/11/2005 you wrote 

  >To : rohit at cfl.co.nz,delphi at ns3.123.co.nz 

  >CC : 

  >From: Kyley Harris, kyleyharris at gmail.com 

  >Content Type: text/plain 

  >Attached: 

  > 

  >There are two basic ways to send a string, seeing as we are talking 

  >postmessage, 

  >here is the fugly one. 

  > 

  >p:phar; 

  > 

  >GetMem(p,length(data)); 

  >move(data[1],p^,length(data)); 

  >postmessage(bla bla , integer(p)); 

  > 

  >remember to free mem on the other side. 

  > 

  >Better and nicer way 

  > 

  >TString = class(TObject) 

  > property data:string; 

  >end; 

  > 

  >Create and send a reference to this, and free it when you are finished. 

  >remember none of these options is safe outside of your own application. 

  > 

  > 

  > 

  >On Thu, 24 Nov 2005 17:43:51 +1300, Rohit Gupta <rohit at cfl.co.nz> wrote: 

  > 

  >> I cant see how it can be safe. I was stumped as well when I wanted 

  >> to send a string in a message. I had to abandon my ideas.... :-( Let 

  >> me know if you have any joy. 

  >> 

  >> From:     "Paul Lowman" <paul_lowman at xtra.co.nz> 

  >> To:     "Delphi List" <delphi at delphi.org.nz> 

  >> Date sent:     Thu, 24 Nov 2005 16:22:04 +1300 

  >> Copies to:      

  >> Subject:     [DUG] Reference counting 

  >> Send reply to:     NZ Borland Developers Group - Delphi List 

  >> <delphi at ns3.123.co.nz> 

  >>     <mailto:delphi-request at ns3.123.co.nz?subject=unsubscribe> 

  >>     <mailto:delphi-request at ns3.123.co.nz?subject=subscribe> 

  >> 

  >> [ Double-click this line for list subscription options ] 

  >> 

  >> Heres one for the gurus - 

  >> 

  >> Assume a long string variable is declared locally to a method and is 

  >> assigned a string and the string variable is then typecast as an integer 

  >> and 

  >> used in - say - a windows message by assigning it to the message lparam. 

  >> 

  >> The question is when the message is received by another form / thread is 

  >> it 

  >> valid to then typecast the lparam back to a string and use it ? 

  >> 

  >> I have tried many variations of this scenario and it seems to work OK 

  >> but am 

  >> uneasy about whether or not this is safe. I assume it isn't as the local 

  >> string variable (which points to the actual string) is on the stack and 

  >> is 

  >> not maintained after the method is exited but what I really am concerned 

  >> about is the reference count for the string - has it been increased by 

  >> typecasting it to an integer / pointer whatever ... 

  >> 

  >> I have used some of Marco Cantu's code to try and examine the strings 

  >> reference count and it always appears to be -1 if the string is a local 

  >> variable although it works correctly for field or global. 

  >> 

  >> All very confusing :-) 

  >> 

  >> I would like to know how the code knows when to inc / dec / dispose the 

  >> stirng / array reference count. 

  >> 

  >> Cheers 

  >> 

  >> Paul Lowman 

  >> 

  >> _______________________________________________ 

  >> Delphi mailing list 

  >> Delphi at ns3.123.co.nz 

  >> http://ns3.123.co.nz/mailman/listinfo/delphi 

  >> Regards 

  >> 

  >> Rohit 

  >> 

  >> ====================================================================== 

  >> CFL - Computer Fanatics Ltd. 21 Barry's Point Road, AKL, New Zealand 

  >> PH (649) 489-2280 

  >> FX (649) 489-2290 

  >> email rohit at cfl.co.nz or r.gupta at xtra.co.nz 

  >> ====================================================================== 

  >> 

  >> 

  >> _______________________________________________ 

  >> Delphi mailing list 

  >> Delphi at ns3.123.co.nz 

  >> http://ns3.123.co.nz/mailman/listinfo/delphi 

  > 

  > 

  > 

  >-- 

  >Kyley Harris 

  >+64-21-671821 

  >_______________________________________________ 

  >Delphi mailing list 

  >Delphi at ns3.123.co.nz 

  >http://ns3.123.co.nz/mailman/listinfo/delphi 

  >



------------------------------------------------------------------------------
        Gary Benner  
        e-Engineer, Lecturer, and Software Developer 

     123 Internet Limited 
        Waiariki Institute of Technology 
        Sunshine Garden Bag Co. 
        Sommnet.com Limited 
        Mob: 021 966 992 
        Email: gary at 123.co.nz  


  Ref#: 41006




------------------------------------------------------------------------------


  _______________________________________________
  Delphi mailing list
  Delphi at ns3.123.co.nz
  http://ns3.123.co.nz/mailman/listinfo/delphi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ns3.123.co.nz/pipermail/delphi/attachments/20051124/03a1df22/attachment-0001.html


More information about the Delphi mailing list