5월, 2019의 게시물 표시

C# 기본적으로 알아야 할 사항

https://docs.microsoft.com/ko-kr/dotnet/csharp/programming-guide/inside-a-program/coding-conventions [개체 이니셜라이저 사용] // Object initializer. var instance3 = new ExampleClass { Name = "Desktop" , ID = 37414 , Location = "Redmond" , Age = 2.3 }; // Default constructor and assignment statements. var instance4 = new ExampleClass(); instance4.Name = "Desktop" ; instance4.ID = 37414 ; instance4.Location = "Redmond" ; instance4.Age = 2.3 ; [배열을 사용할때 참고] // Preferred syntax. Note that you cannot use var here instead of string[]. string [] vowels1 = { "a" , "e" , "i" , "o" , "u" }; // If you use explicit instantiation, you can use var. var vowels2 = new string [] { "a" , "e" , "i" , "o" , "u" }; // If you specify an array size, you must initialize the elements one at a time. var vowels3 = new string [ 5 ]; vowels3[ 0 ] = ...

How to align sectors for unbuffered writes

The following C++ example shows how to align sectors for unbuffered file writes. The Size variable is the size of the original data block you are interested in writing to the file. #include <windows.h> #define ROUND_UP_SIZE(Value,Pow2) ((SIZE_T) ((((ULONG)(Value)) + (Pow2) - 1) & (~(((LONG)(Pow2)) - 1)))) #define ROUND_UP_PTR(Ptr,Pow2)  ((void *) ((((ULONG_PTR)(Ptr)) + (Pow2) - 1) & (~(((LONG_PTR)(Pow2)) - 1)))) void main() { // Function code     DWORD BytesPerSector = 0; // obtained from the GetFreeDiskSpace function.     DWORD Size = 0; // buffer size of your data to write // ... obtain data here // sample data     BytesPerSector = 65536;     Size = 15536; //    // Ensure you have one more sector than Size would require.    SIZE_T SizeNeeded = BytesPerSector + ROUND_UP_SIZE(Size, BytesPerSector);      // Replace this statement with any allocation routine....

CreateFile() DesiredAccess vs SharedMode 관계

출처 → https://kuaaan.tistory.com/407?category=91638 DesiredAccess는 기존의 열린 SharedMode의 부분집합이어야 하고 SharedMode는 기존의 열린 DesiredMode의 전체집합이어야 한다. ➤ hFile1 = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ); hFile2 = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE );   성공 hFile1(GENERIC_READ)로 열렸기 때문에 hFile2의 SharedMode가 이를 만족 hFile2 = CreateFile(argv[1], GENERIC_READ, FILE_SHARE_WRITE );   실패 hFile1(GENERIC_READ)인데 SharedMode로 FILE_SHARE_WRITE이므로 ➤ hFile1 = CreateFile(argv[1], GENERIC_READ | GENERIC_WRITE ,                          FILE_SHARE_READ); hFile2 = CreateFile(argv[1], GENERIC_READ,                          FILE_SHARE_WRITE );   실패 hFile2의 SharedMode가 hFile1의 DesiredAccess를 포함한 셋이어야 하는데 아니므로. ...