[omniORB] Returning a cache sequence
Huw Rogers
count0@building2.co.jp
Wed, 27 Jun 2001 08:44:57 +0900
The copy ctor shouldn't
be any less efficient than the other method,
and is simpler.
Multiple overlapping read operations on const data
(copy ctor from, assign from, etc.) are normally
not a hazard unless the read has internal write
consequences such as writing access logs, audits,
incrementing counters etc.
However you will want to isolate reading / copying
from writing, so unless cacheCustomers
is never changed, you will in any case need
to lock it where you change it, and lock it
again where you copy/read it.
-Huw
Matthew Berry wrote:
>
> Hi,
>
> I have defined a structure Customer and an operation:
>
> sequence<Customer> getCustomers()
>
> Now when I initialise the "in-memory-database" server I read all the
> customers into a sequence "cacheCustomers"
>
> What I what to know is the most efficient way of returning (a copy of) the
> customers in the above operation?
>
> Option 1, using the sequence copy constructor:
>
> return new CustomerSeq(cacheCustomers)
>
> Option 2, using the data constructor (which H&V advises against, but I think
> is more efficient):
>
> return new CustomerSeq(cacheCustomers.length(), cacheCustomers.length(),
> cacheCustomers.get_buffer(), 0)
>
> Are both of these options thread-safe? Do I need to protect access to
> "cacheCustomers", because I could potentially two clients requesting the
> customer list simultaneously?
>
> TiA,
>
> Matthew