.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

Marshall Copy a C++ ushort buffer into a C# ushort buffer.

Posted By:      Posted Date: September 21, 2010    Points: 0   Category :.NET Framework
I have a C++ dll that returns an unsigned short data buffer. I want to copy this data using my C# copy however the Marshall.Copy only supports "short" data type. What is the most efficient way to to get this data into a ushort buffer in C#?

View Complete Post

More Related Resource Links

HowTo Marshal C++ enums and copy buffer of unsigned 16bit integer


Hi together,

I'm trying to wrap an API of a digital camera SDK (unmanaged C++). Some of the functions a working, but some of them ... :(

1. HowTo marshal  C++  enums?

This is a part of the api.h file:



	DCAM_DATATYPE_UINT8	=	0x00000001,	/* bit 0 */
	DCAM_DATATYPE_UINT16	=	0x00000002,	/* bit 1 */
	DCAM_DATATYPE_UINT32	=	0x00000008,	/* bit 3 */
	DCAM_DATATYPE_MOSAIC8	=	0x00010000,	/* bit 16, 8bit mosaic */
	DCAM_DATATYPE_MOSAIC16	=	0x00020000,	/* bit 17, 16bit mosaic */
	DCAM_DATATYPE_RGB24	=	0x00040000,	/* bit 18, 8bit*3, [ r0, g0, b0], [r1, g1, b1] */
	DCAM_DATATYPE_RGB48	=	0x00100000,	/* bit 20, 16bit*3, [ r0, g0, b0], [r1, g1, b1] */


BOOL DCAMAPI dcam_getdatatype			( HDCAM h, DCAM_DATATYPE* pType );
BOOL DCAMAPI dcam_setdatatype			( HDCAM h, DCAM_DATATYPE type );<br/>


And this is what I wrote in C#:

Windows UDP Socket Buffer (Maximum)

I am receiving on a socket (C#) and setting the UDP buffer size to br 10 Mb - and creating 16 such sockets. But I see missed UDP packets (they have  a unique seq number in them). When I read back "ReceiveBufferSize" it return the size I set it to - 10Mb.   My question is - what is the maximum internal socket buffer size allowed by Windows (Win Server 2008) ?   Wierdly when I also start Netmon in the background on the receiving machine - I do not see any missed packets.   Does Netmon modify internal windows socket buffers (increase them) - how can I go about doing this with my app ?   Thanks

TypePerf, Buffer Cache Hit Ratio, Page Life expectancy and some other counters....

Hello, I 've scheduled a Task on a Windows 2008 R2 Server (a Blade with 2 Processors (6 core HT) and 18 GB RAM) to check some SQL Server 2008 Performance Counters. The task runs TypePerf that checks the Counters every 15 seconds for 10 minutes. The task is scheduled every hour. The strange result is that Buffer Cache Hit Ratio, Page Life expectancy and some other Counters are ALWAYS = 0 but if I run PerfMon, Buffer Cache Hit Ratio is 100 and  Page Life expectancy >>>> 300. Any Idea? Thank youLuca Bovo MCTS - MCITP SQL Server 2005 (Database Administrator and Database Developer)

SQL Server 2005 buffer cache

Hello! I try to find out what objects use buffer cache. As example, in Oracle there is fixed table x$bh. This table gives us infomation about buffer cache on per block basis. Is there similar view or table in SQL Server 2005? How can I find out what table uses most of buffer cache?

buffer data from a sql server database file

I'm in need of a sample code that will let me buffer data from a database so that I can go next> and <prev in a database file. Does someone have an idea on now to do this. Joe      Toppers BBS http://toppersbbs.dtdns.net C# Windows and Console applications. PHP, Mysql. HTML

Don't Understand Checkpoint / Buffer Cache Explanation in BOL

Checkpoints and the Active Portion of the Log     ? Checkpoints flush dirty data pages from the buffer cache of the current database to disk. This minimizes the active portion of the log that must be processed during a full recovery of a database. During a full recovery, the following types of actions are performed: The log records of modifications not flushed to disk before the system stopped are rolled forward. All modifications associated with incomplete transactions, such as transactions for which there is no COMMIT or ROLLBACK log record, are rolled back.   I don't understand this BOL page... From what I read in the first sentence above, the following must be true: I understand that SQL Server apparently doesn't save updated data directly to disk but stores it in RAM (the so-called Buffer Cache) until either this RAM buffer is full or until a checkpoint operation is executed.   If this is tue, Isn't this quite dangerous? What happens if the server is powered off? Are all updates that had been stored in the Buffer Cache / Log Cache lost? After a server restart, how can "The log records of modifications not flushed to disk before the system stopped" possibly be "rolled forward" if they had been stored in the Buffer Cache? After a server restart the Buffer Cache and the Log Cache must be empty! So there are no unsaved l

C# panel double buffer




i still have problem with the double buffer for a panel control. what i did is the following:


 first i create  a new class derived from panel and set the
control styles in the constructor, as shown below:


Code Snippet

public class DoubleBufferPanel : Panel


    public DoubleBufferPanel()


        // Set the value of the double-buffering style bits to true.

        this.DoubleBuffered = true;

        this.SetStyle(ControlStyles.AllPaintingInWmPaint |

        ControlStyles.UserPaint |


Issue with the buffer size of DFT!!


Hi Team,

I have a question on defining buffer size in ssis dataflow task

Existing table with 207 rows size is 520KB. I have to load 10000 rows at the max, can I increase buffer size of the DFT to 26MB my server Ram is 2GB and I am running this on SQL Server 2000 database?



Clear the socket buffer

I am working with a socket code in C#
The problem is that clients get's randomly disconnected from the server.
Is the right thing to do to clear the buffer?
How do I clear the buffer?

        private void dataArrival(IAsyncResult iAr)  

deadlocked on lock | communication buffer resources


I've recently started getting two deadlock errors:

deadlocked on lock | communication buffer resources


Transaction was deadlocked on lock resources with another process

There haven't been any recent changes to the system that offer a readily apparent explanation regarding why my users have started getting these errors in their browsers. I got a DBA to capture some data in Profiler and I'm posting the XML from one of the deadlocks at the bottom of this.

The description of the scenario is that there is a ASP.NET 1.1 web app and a VC++7 Windows service both running against a SQL Server 2005 clustered database. The deadlocks are happening between a simple select statement that doesn't use any joins and a simple update statement that is updating the same table. Neither process is using explicit SQL transactions (i.e. there is no explicit Begin Transaction) nor are they using any kind of hints (like NOLOCK or READUNCOMMITTED). But, I can't see why they should need to.

I have captured staticts on the DB per another thread on this subject and the results were:

wait_type wait_time_s pct running_pct

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


SSIS 2005 Buffer Manager Issue


Hi All,

I am facing Buffer Error while running my SSIS Package. I have configured BufferTempStoragePath Property of Data Flow task. Even though I am getting the following Buffer Manager Error.

Description: The buffer manager cannot create a temporary storage file on any path in the BufferTempStoragePath property. There is an incorrect file name or no permission.  End Error  Error: 2010-09-24 07:40:01.01     Code: 0xC0047048     Source: DFT Load Fact Data DTS.Pipeline     Description: The buffer manager cannot create a temporary storage file on any path in the BufferTempStoragePath property

Is there any other property settings or workaround to resolve the issue?



Why can't you increment ushort or byte variables (+1)??


According to the C# built-in types table at http://msdn.microsoft.com/en-us/library/ya5y69ds.aspx,

the ushort is a 16-bit unsigned integer.  The byte is an 8-bit unsigned integer.

So when I declare:

public byte x;

ushort y;

Neither of those, I can not do the following:

x = x+1;


i get an error: "Cannot implicitly convert type "int" to "ushort" or to "byte".

Why is this?  They are both integer-grade data types?  I don't want to use the "int" type because that is a 32-bit signed integer, requiring more memory than I need.


buffer manager free pages decrease though the sql server has a lot memory

we found the backup frequently fails due to insufficient memory, when checked the buffer memory, found it always decreases, can we purge something in buffer to free more pages?

SocketAsyncEventArgs buffer not ready



I am using async socket operations to read data streamed from a server. I need to use async because commands can be sent to the server and I will receive response messages in an async manner. My problem though is that sometimes in our production environment the buffer that the Async operations write to isn't "ready" when I get a Completed event. That is; I read the BytesTransferred property on the SocketAsyncEventArgs object saying e.g. that 114 bytes was transferred, but the buffer is not updated with any content (all zeros). Since the HW in production is a dual quad core processor with hyper threading I assumed that it might be related to the memory model. But even if the buffer is marked as volatile the same problem occurs. 

The server is running Windows Server 2008 R2 Std Edition (x64) with 2xIntel Xeon E5520.

I hope you are able to put me on track here. I have done a lot of async server and client applications, but have never seen this issue before.



A time-out occurred while waiting for buffer latch -- type 2 Not continuing to wait.



when we are executing query in sql server 2005(SP2) we are getting below error.

A time-out occurred while waiting for buffer latch -- type 2, bp 03BD8650, page 1:15883707, stat 0x1c0040d, database id: 7, allocation unit Id: 72057608604745728, task 0x54FA8118 : 5, waittime 300, flags 0x3a, owning task 0x009291F8. Not continuing to wait.

Physical Memory=8G.

Memory Utilization is also looking normal.

please let me know how to avoid this problem and provide me if any article is available.





venkat reddy

Buffer Size error when retrieving Metadata - How to increase size?


I am trying to retrieve the MetaData from the WCF Service using the following method.

// Create a MetadataExchangeClient for retrieving metadata.
EndpointAddress mexAddress = new EndpointAddress( uri );
MetadataExchangeClient mexClient = new MetadataExchangeClient( mexAddress );
// Retrieve the metadata for all endpoints using metadata exchange protocol (mex).
MetadataSet metadataSet = mexClient.GetMetadata();

How do I increase the buffer size?


Fileupload + Part Buffer + Zip


Let me first explain what i am after. I want to Uploade a LARGE file, Several of gigs, so i DO NOT want to uploade the entire to memory and then write it physicially to the hdd.

I also want the target file to be zipped.


what i have tried to do is

            FileUpload FileUpload1 = (FileUpload)LoginView1.FindControl("FileUpload1");
            string targetName = "C:\\Uploads\\" + new FileInfo(FileUpload1.PostedFile.FileName).Name;
            int numberOFExten = targetName.LastIndexOf('.');
            targetName = targetName.Remove(numberOFExten);
            targetName = targetName + ".zip";
            using (FileStream target = new FileStream(targetName,FileMode.Create,FileAccess.Write))
              using (GZipStream alg = new GZipStream(target, CompressionMode.Compress))

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend