468,766 Members | 1,532 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,766 developers. It's quick & easy.

Redesign of a class that used alot of pointers

Hi,

I have this old class that was used for logging error messages and I thought
it would be a good exercise (for me) to convert it to .Net specifically c#.

This class uses two typed pointer lists to process log messages. One is the
input queue for incoming messages and the other is the processing queue for
processing the messages. The thread that does the processing will process
all the objects on the procesing queue and then swap the input and
processing queues and then process those messages. This allows for the
incoming messages to be added to a queue with out the potential of being
blocked by the processing thread.

The last part about swapping the queues (which is obviously done via
pointers) is where I'm not sure what to do in c#.

Anyone have any ideas?

Thanks
Nov 16 '05 #1
4 1045
It sounds like you are converting a C++ class. You can declare unsafe code
blocks and use pointers in C#, but the general idea is to avoid pointers
except when they really do help a provable performance issue. In my view,
pointers are seldom worth the trouble and risk in a line of business
application.

In C#, a reference to an object usually takes the place of a pointer. I
would imagine that you'd have two instances of a queue class, and refer to
one or the other, e.g.:

MyQueue inputq = new MyQueue();
MyQueue processingq = new MyQueue();
// sometime later
DoWork(processingq);
DoWork(inputq);
// or maybe even
processingq.DoWork();
inputq.DoWork();

--Bob

"Jason" <yo@yo.com> wrote in message
news:u4**************@TK2MSFTNGP14.phx.gbl...
Hi,

I have this old class that was used for logging error messages and I
thought
it would be a good exercise (for me) to convert it to .Net specifically
c#.

This class uses two typed pointer lists to process log messages. One is
the input queue for incoming messages and the other is the processing
queue for processing the messages. The thread that does the processing
will process all the objects on the procesing queue and then swap the
input and processing queues and then process those messages. This allows
for the incoming messages to be added to a queue with out the potential of
being blocked by the processing thread.

The last part about swapping the queues (which is obviously done via
pointers) is where I'm not sure what to do in c#.

Anyone have any ideas?

Thanks

Nov 16 '05 #2
> The last part about swapping the queues (which is obviously done via
pointers) is where I'm not sure what to do in c#.


You simply swap the references. .NET references are pretty close to what
pointers will provide you with.
Nov 16 '05 #3

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
The last part about swapping the queues (which is obviously done via
pointers) is where I'm not sure what to do in c#.


You simply swap the references. .NET references are pretty close to what
pointers will provide you with.


wouldn't that be a very expensive option ? If I understand it correctly
swapping the references would copy every object in the queue rather than
just the addresses. If I had alot of messages in the queues wouldn't that be
too time consuming cpu wise?

Thanks

Nov 16 '05 #4

"Jason" <yo@yo.com> wrote in message
news:us**************@TK2MSFTNGP09.phx.gbl...

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
The last part about swapping the queues (which is obviously done via
pointers) is where I'm not sure what to do in c#.


You simply swap the references. .NET references are pretty close to what
pointers will provide you with.


wouldn't that be a very expensive option ? If I understand it correctly
swapping the references would copy every object in the queue rather than
just the addresses. If I had alot of messages in the queues wouldn't that
be too time consuming cpu wise?


You understand it wrong. The reference is nothing but a 4byte(or possiby 8
on 64 bit machines, I"m not sure) value that is used to locate the object's
actual memory pointer. So swapping the references would simply swap that 4
byte value between the two.
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Tim Parkin | last post: by
15 posts views Thread by Andrew Brampton | last post: by
12 posts views Thread by James Brown | last post: by
3 posts views Thread by fernandez.dan | last post: by
6 posts views Thread by Itay_k | last post: by
14 posts views Thread by Dennis | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.