0

I am developing a call recording application in C#.net using pcap.net library. For packet capturing i am using Wireshark's Dumpcap.exe. And the packet files are creating in 5 second duration. To read each packet file what i have done is

   OfflinePacketDevice selectedDevice = new OfflinePacketDevice(filename);
            using (PacketCommunicator communicator =
           selectedDevice.Open(65536,                                  // portion of the packet to capture
                // 65536 guarantees that the whole packet will be captured on all the link layers
                               PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
                               0))                                  // read timeout
            {

                communicator.ReceivePackets(0, DispatcherHandler);

In DispatcherHandler method i am processing each packets. DispatcherHandler call takes 0 seconds for each file .

I am getting delay when prcessing the RTP packets packets in the same method..

To identify rtp packets I used ordered dictionary with key as ipadrress+portnumber. So I need to check whether this key exists in dictionary when each rtp packet comes. This task getting slower in processing each dump file.

if (objPortIPDict.Contains(ip.Source.ToString().Replace(".", "") + port))
{
 // here i write the rtp payload to a file
}
Mask
  • 647
  • 2
  • 9
  • 21

1 Answers1

1

I read a couple of strange things:

1) Why use Contains in Dictionary?

objPortIPDict.Contains(ip.Source.ToString().Replace(".", "") + port)

If objPortIPDict is a dictiaonary use ContainsKey

2) Derivates from first. If this is a Dictionary, its ContainsKeyhas O(1) time of execution, so can not be affected by amount of data in dictionary itself.

Yes, it can be affected, if the amount of data becomse so big, that entire application becomes slower, but pick time will remain always constant in regard of current application state domain.

Tigran
  • 61,654
  • 8
  • 86
  • 123
  • Exactly. It's O(1) because Dictionary uses hash codes, which are of course calculated as O(1). If the dictionary became so full that there were a lot of hash code collisions, it will become a lot slower than O(1) - but you are likely to run out of memory before that happens (at least for a 32 bit program). – Matthew Watson Jan 09 '13 at 13:13
  • **objPortIPDict** is an OrderedDictionary. In that keys inserting are not numbers, its format like **"10.10.10.50,4000"**. Will it get slower when searching the key? – Mask Jan 09 '13 at 14:15
  • if you use ContainsKey, will not. – Tigran Jan 09 '13 at 14:19
  • **Contains** Determines whether the System.Collections.Specialized.OrderedDictionary collection contains a specific key. – Mask Jan 10 '13 at 09:34