|
Joe Pluta wrote: > ... > There are other reasons to return a pointer to private storage. Again, I'm > talking in general terms rather than specifically in RPG terms, but it is > much easier (and faster) to compare two pointers to structures rather than > to compare the entire contents of the structure. Let's say a method is > designed to return one of several structures. It can either create a new > clone of the structure each time, or a pointer to an internally defined > structure. If this method always returns a pointer to a specific internally > defined structure, a programmer may use a much more efficient pointer > comparison to determine equality. It's even faster, and just as easy, to compare two handles to structures. The service can communicate with its consumers by say an integer that's an index into an array of pointers. You still have the quick comparison without the consumer having the ability to look inside (or worse, change) the private structure. (A real handle would probably be an encoding of some unique value plus an array index, to prevent accidental reuse.) > Anyway, my point is that determining whether a given technique is "right" or > "wrong" really depends upon the implementation and the reason. No argument there. But as a rule of thumb, giving out a pointer to a module's private storage can lead to hard-to-solve problems, like the one that started this thread. By the way, speaking of "thread", two modules having stored pointers to one module's static storage is one of the thread-safety issues that RPG's THREAD(*SERIALIZE) doesn't protect you against In a thread-safe application, you would have to add your own serialization to access that shared storage.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.