public static void TestChaArrayUseLength() { Random rnd = new Random(); int maxLengthCh = 512 * 1024 * 1024; Console.WriteLine("Test char array (length):"); char[] buffer = new char[maxLengthCh]; char[] templateCh = new char[16] { '1', '2', '3', '4', '5', '6', '7', '8', '1', '2', '3', '4', '5', '6', '7', '8' }; dh.StartWatch(); int position = maxLengthCh; for (int i = 0; i < 200; i++) { position = maxLengthCh - templateCh.Length; while (position >= 0) { rnd.Next(10); Buffer.BlockCopy(templateCh, 0, buffer, position << 1, templateCh.Length << 1); position -= templateCh.Length; } } dh.StoptWatch(); templateCh = null; buffer = null; GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); }
public static void TestStringBuilderWithCharArray() { Random rnd = new Random(); int maxLength = 256 * 1024 * 1024; StringBuilder sb = new StringBuilder(maxLength, maxLength); Console.WriteLine("Test stringBuilder char array :"); char[] templateCh = new char[16] { '1', '2', '3', '4', '5', '6', '7', '8', '1', '2', '3', '4', '5', '6', '7', '8' }; string templateTmp = ""; dh.StartWatch(); for (int i = 0; i < 400; i++) { while (sb.Length < maxLength) { rnd.Next(10); sb.Append(templateCh); } templateTmp = sb.ToString(); templateTmp = ""; sb.Clear(); } sb = null; dh.StoptWatch(); GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); }
public static void TestQuickSort(int n) { Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("Test Comparer Quick Sort"); int[] array = new int[n]; Console.WriteLine("Generate data"); RandomIteratorUsafeXorshiftEn rnd1 = new RandomIteratorUsafeXorshiftEn(n + 1); FastRandom rnd = new FastRandom(); dh.StartWatch(); for (int i = 0; i < n; i++) { array[i] = rnd.Next(); } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Sort"); dh.StartWatch(); var c = new CustomIntComparerD(); Quicksort(array, 0, n - 1, c.Compare); dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); array = null; GarbachCollectorHelper.GBForceRun(); }
unsafe public static void TestQuickSort(int n) { Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("Test Pointer Quick Sort"); int[] array = new int[n]; Console.WriteLine("Generate data"); dh.StartWatch(); RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(n + 1); for (int i = 0; i < n; i++) { array[i] = rnd.Next32(); } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Sort"); dh.StartWatch(); fixed(int *start = &array[0], end = &array[n - 1]) { Quicksort(start, end); } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); array = null; GarbachCollectorHelper.GBForceRun(); }
public static void TestStringBuilder() { int maxLength = 256 * 1024 * 1024; StringBuilder sb = new StringBuilder(maxLength, maxLength); Console.WriteLine("Test StringBuilder :"); string templateSB = "1234567812345678"; string templateTmp = ""; dh.StartWatch(); for (int i = 0; i < 400; i++) { while (sb.Length < maxLength) { sb.Append(templateSB); } templateTmp = sb.ToString(); templateTmp = ""; sb.Clear(); } sb = null; dh.StoptWatch(); GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); }
public static void TestArrayWithDictionaryUseLength() { int maxLengthCh = 512 * 1024 * 1024; int maxLengthCh2 = maxLengthCh << 1; Console.WriteLine("Test char array with dictionary (length):"); char[] buffer = new char[maxLengthCh]; char[][] templateCh = { " apple".ToCharArray(), " town".ToCharArray(), " array".ToCharArray(), " summer".ToCharArray(), " winter".ToCharArray(), " aplril".ToCharArray(), " customer".ToCharArray(), " support".ToCharArray(), " laptop".ToCharArray(), " cross-domain".ToCharArray() }; int n = templateCh.Length; int[] sizes = new int[n]; int[] sizes2 = new int[n]; int sizeTmp = 0; for (int i = 0; i < n; i++) { sizeTmp = templateCh[i].Length; sizes[i] = sizeTmp; sizes2[i] = sizeTmp << 1; } dh.StartWatch(); int position = maxLengthCh; int position2 = maxLengthCh << 2; int templateLenghtCh2 = templateCh.Length << 1; int randomIndex = 0; Random rnd1 = new Random(); char[] tmpChArray = null; n--; for (int i = 0; i < 200; i++) { randomIndex = n;// rnd1.Next(n); tmpChArray = templateCh[randomIndex]; templateLenghtCh2 = tmpChArray.Length << 1; position2 = maxLengthCh2 - templateLenghtCh2; while (position2 >= 0) { Buffer.BlockCopy(tmpChArray, 0, buffer, position2, templateLenghtCh2); //randomIndex = rnd1.Next(n); tmpChArray = templateCh[randomIndex]; templateLenghtCh2 = tmpChArray.Length << 1; position2 -= templateLenghtCh2; } } dh.StoptWatch(); templateCh = null; buffer = null; templateCh = null; sizes = null; sizes2 = null; GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); }
public static void TestRandom() { Random rnd = new Random(); Console.WriteLine("Test Random generator : "); dh.StartWatch(); for (long i = 0; i < 20000000000; i++) { rnd.Next(1, 10); } dh.StoptWatch(); GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); }
public static void TestArrayCopyBlockCopy1(int iterationCount = 1) { Console.WriteLine("---------------------------------------------------------------"); Console.WriteLine("Copy array using block copy -- :"); Console.WriteLine("Generating data ... "); dh.StartWatch(); int n = 1024 * 1024; RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(1024 * 1024); rnd.Reset(); byte[] destArray = new byte[n]; byte[] sourceArra = new byte[256]; Buffer.BlockCopy(rnd.values, 0, sourceArra, 0, 256); byte index = rnd.bNext(); int position = 0; dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Executing - > ... "); dh.StartWatch(); for (int k = iterationCount * 1024; k > 0; --k) { position = n; //index = rnd.bNext(); index = 1; position -= index; while (position > 0) { Buffer.BlockCopy(sourceArra, 0, destArray, position, index); index = rnd.bNext(); position -= index; } } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); destArray = null; GarbachCollectorHelper.GBForceRun(); }
public static void TestSort(int n) { Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("Test Comparer Sort"); int[] array = new int[n]; Console.WriteLine("Generate data"); RandomIteratorUsafeXorshiftEn rnd1 = new RandomIteratorUsafeXorshiftEn(n + 1); FastRandom rnd = new FastRandom(); Random random = new Random(); dh.StartWatch(); for (int i = 0; i < n; i++) { array[i] = rnd.Next(); } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); /* * byte[] byteArray = new byte[256]; * dh.StartWatch(); * for (int i = 0; i < n; i++) * { * array[i] = byteArray[rnd1.bNext()]; * } * dh.StoptWatch(); * Console.WriteLine(dh.GetMessage()); * * dh.StartWatch(); * for (int i = 0; i < n; i++) * { * array[i] = rnd1.Next16(); * } * dh.StoptWatch(); * Console.WriteLine(dh.GetMessage()); */ Console.WriteLine("Sort"); dh.StartWatch(); Array.Sort(array, new CustomIntComparerD()); dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); array = null; GarbachCollectorHelper.GBForceRun(); }
public static void TestArrayCopyIndexing1(int iterationCount = 1) { Console.WriteLine("---------------------------------------------------------------"); Console.WriteLine("Copy array using for(i++) :"); Console.WriteLine("Generating data ... "); dh.StartWatch(); int n = 1024 * 1024 * 1024; RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(1024 * 1024); rnd.Reset(); byte[] destArray = new byte[1024 * 1024 * 1024]; byte[] sourceArra = new byte[256]; Buffer.BlockCopy(rnd.values, 0, sourceArra, 0, 256); byte index = rnd.bNext(); int position = 0; dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Executing --i > ... "); dh.StartWatch(); for (int k = iterationCount; k > 0; --k) { position = n; while (position - index >= 0) { for (byte j = index; j > 0; --j) { --position; destArray[position] = sourceArra[j]; } index = rnd.bNext(); } } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); destArray = null; GarbachCollectorHelper.GBForceRun(); }
public static void TestQuickSort(int n) { var cc = new CustomIntComparerPointer(); CustomCompareDelegate del = new CustomCompareDelegate(cc.Compare); IntPtr ptr = Marshal.GetFunctionPointerForDelegate(del); // Получили указатель на ту самую функцию void *p = ptr.ToPointer(); var d = (CustomCompareDelegate)Marshal.GetDelegateForFunctionPointer((IntPtr)p, typeof(CustomCompareDelegate)); Console.WriteLine(d(2, 3)); Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("Test Comparer Quick Sort"); int[] array = new int[n]; Console.WriteLine("Generate data"); RandomIteratorUsafeXorshiftEn rnd1 = new RandomIteratorUsafeXorshiftEn(n + 1); FastRandom rnd = new FastRandom(); dh.StartWatch(); for (int i = 0; i < n; i++) { array[i] = rnd.Next(); } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Sort"); dh.StartWatch(); var c = new CustomIntComparerPointer(); Quicksort(array, 0, n - 1, d); dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); array = null; GarbachCollectorHelper.GBForceRun(); }
public static void TestQuickSortTaskLimited(int n, int limit) { Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("Test Pointer Quick Sort Limited "); int[] array = new int[n]; Console.WriteLine("Generate data"); dh.StartWatch(); RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(n + 1); for (int i = 0; i < n; i++) { array[i] = rnd.Next32(); } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Sort"); dh.StartWatch(); QuicksortTaskLimited(array, 0, n - 1, limit); dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); array = null; GarbachCollectorHelper.GBForceRun(); }
public static void TestSort(int n) { Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("Test Pointer Sort "); int[] array = new int[n]; Console.WriteLine("Generate data"); dh.StartWatch(); RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(n + 1); for (int i = 0; i < n; i++) { array[i] = rnd.Next32(); } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Sort"); dh.StartWatch(); Array.Sort(array); dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); array = null; GarbachCollectorHelper.GBForceRun(); }
public static void TestCharArrayCopyExtensions() { Random rnd = new Random(); int maxLengthCh = 512 * 1024 * 1024; int maxLengthCh2 = maxLengthCh << 1; Console.WriteLine("Test char array CopyExtensions:"); char[] buffer = new char[maxLengthCh]; char[] templateCh = new char[16] { '1', '2', '3', '4', '5', '6', '7', '8', '1', '2', '3', '4', '5', '6', '7', '8' }; dh.StartWatch(); { int position = maxLengthCh; int position2 = maxLengthCh << 2; int templateLenghtCh = templateCh.Length; for (int i = 0; i < 200; i++) { position = maxLengthCh - templateLenghtCh; while (position >= 0) { rnd.Next(10); CopyExtensions.CopyMemoryCh(templateCh, 0, buffer, position, templateLenghtCh); //Buffer.BlockCopy(templateCh, 0, buffer, position2, templateLenghtCh); position -= templateLenghtCh; } } } dh.StoptWatch(); templateCh = null; buffer = null; GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); }
public static void TestListVsArray(int n = Int32.MaxValue, int iteration = 100) { byte tmp = 0; byte[] arrayTest = new byte[n]; Console.WriteLine("----------------------------------------------------"); Console.WriteLine("Fill array : "); dh.StartWatch(); for (int j = 0; j < iteration; j++) { for (int i = 0; i < n; i++) { arrayTest[i] = tmp; } } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); arrayTest = null; Console.WriteLine("GB "); dh.StartWatch(); GarbachCollectorHelper.GBForceRun(); dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); List <byte> list = new List <byte>(); Console.WriteLine("Fill list add "); dh.StartWatch(); for (int j = 0; j < iteration; j++) { for (int i = 0; i < n; i++) { list.Add(tmp); } list.Clear(); } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); list = null; Console.WriteLine("GB "); dh.StartWatch(); GarbachCollectorHelper.GBForceRun(); dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Fill list capasity "); List <byte> listCapasity = new List <byte>(n); dh.StartWatch(); for (int j = 0; j < iteration; j++) { for (int i = 0; i < n; i++) { listCapasity.Add(tmp); } listCapasity.Clear(); } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); listCapasity = null; Console.WriteLine("GB "); dh.StartWatch(); GarbachCollectorHelper.GBForceRun(); dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Fill list capasity [] "); List <byte> listCapasityIndex = new List <byte>(n); dh.StartWatch(); for (int j = 0; j < iteration; j++) { for (int i = 0; i < n; i++) { listCapasityIndex[i] = (tmp); } } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); listCapasityIndex = null; Console.WriteLine("GB "); dh.StartWatch(); GarbachCollectorHelper.GBForceRun(); dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); }
unsafe public static void IterateArray(int n = 1024 *1024, int iteration = 100 *1024) { Console.WriteLine("----------------------------------------------------------"); int value = 0; byte[] array = null; int n1 = n; n1--; Console.WriteLine("Generate array"); dh.StartWatch(); array = new byte[n]; dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Iterate array foreach "); dh.StartWatch(); for (int j = iteration; j != 0; j--) { foreach (int i in array) { value = i; } } dh.StoptWatch(); array = null; GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Generate array"); dh.StartWatch(); array = new byte[n]; dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Iterate array for (i++)"); dh.StartWatch(); for (int j = iteration; j != 0; j--) { for (int i = 0; i < n; i++) { value = array[i]; } } dh.StoptWatch(); array = null; GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Generate array"); dh.StartWatch(); array = new byte[n]; dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Iterate array for (++i)"); dh.StartWatch(); for (int j = iteration; j != 0; j--) { for (int i = 0; i < n; ++i) { value = array[i]; } } dh.StoptWatch(); array = null; GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Generate array"); dh.StartWatch(); array = new byte[n]; dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Iterate array for (i--)"); dh.StartWatch(); for (int j = iteration; j != 0; j--) { for (int i = n - 1; i >= 0; i--) { value = array[i]; } } dh.StoptWatch(); array = null; GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Generate array"); dh.StartWatch(); array = new byte[n]; dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Iterate array for (--i)"); dh.StartWatch(); for (int j = iteration; j != 0; j--) { for (int i = n - 1; i >= 0; --i) { value = array[i]; } } dh.StoptWatch(); array = null; GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Generate array"); dh.StartWatch(); array = new byte[n]; array[n - 1] = 1; array[n - 2] = 2; array[0] = 255; dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Iterate array by pointer < --i"); dh.StartWatch(); fixed(byte *start = &array[0]) { for (int j = iteration; j != 0; j--) { byte *end = start + n; do { value = *(--end); }while (start < end); } } dh.StoptWatch(); array = null; GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Generate array"); dh.StartWatch(); array = new byte[n]; array[n - 1] = 1; array[n - 2] = 2; array[0] = 255; dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Iterate array by pointer <= --i"); dh.StartWatch(); fixed(byte *start = &array[0]) { for (int j = iteration; j != 0; j--) { byte *end = start + n; --end; do { value = *(end); --end; }while (start <= end); } } dh.StoptWatch(); array = null; GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Generate array"); dh.StartWatch(); array = new byte[n]; array[n - 1] = 1; array[n - 2] = 2; array[0] = 255; dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Iterate array by pointer < i--"); dh.StartWatch(); fixed(byte *start = &array[0]) { for (int j = iteration; j != 0; j--) { byte *end = start + n; do { end--; value = *(end); }while (start < end); } } dh.StoptWatch(); array = null; GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Generate array"); dh.StartWatch(); array = new byte[n]; array[n - 1] = 1; array[n - 2] = 2; array[0] = 255; dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Iterate array by pointer <= i--"); dh.StartWatch(); fixed(byte *start = &array[0]) { for (int j = iteration; j != 0; j--) { byte *end = start + n; end--; do { value = *(end); end--; }while (start <= end); } } dh.StoptWatch(); array = null; GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); }
public static void TestAccesToVariables(int n = Int32.MaxValue, int iteration = 100) { byte tmp = 0; byte[] internalArray = new byte[n]; Console.WriteLine("----------------------------------------------------"); Console.WriteLine("Access to internal array "); dh.StartWatch(); for (int j = 0; j < iteration; j++) { for (int i = 0; i < n; i++) { tmp = internalArray[i]; } } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); internalArray = null; Console.WriteLine("GB "); dh.StartWatch(); GarbachCollectorHelper.GBForceRun(); dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); byte[] externalArray = new byte[n]; Console.WriteLine("Access to external array "); dh.StartWatch(); for (int j = 0; j < iteration; j++) { for (int i = 0; i < n; i++) { tmp = externalArray[i]; } } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); externalArray = null; Console.WriteLine("GB "); dh.StartWatch(); GarbachCollectorHelper.GBForceRun(); dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Access to class array "); testClass.classArray = new byte[n]; dh.StartWatch(); for (int j = 0; j < iteration; j++) { for (int i = 0; i < n; i++) { tmp = testClass.classArray[i]; } } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); testClass.classArray = null; Console.WriteLine("GB "); dh.StartWatch(); GarbachCollectorHelper.GBForceRun(); dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Access to prop array "); propArray = new byte[n]; dh.StartWatch(); for (int j = 0; j < iteration; j++) { for (int i = 0; i < n; i++) { tmp = propArray[i]; } } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); testClass.classArray = null; Console.WriteLine("GB "); dh.StartWatch(); GarbachCollectorHelper.GBForceRun(); dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Access to inline array "); inlineArray = new byte[n]; dh.StartWatch(); for (int j = 0; j < iteration; j++) { for (int i = 0; i < n; i++) { tmp = inlineArray[i]; } } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); testClass.classArray = null; Console.WriteLine("GB "); dh.StartWatch(); GarbachCollectorHelper.GBForceRun(); dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); }
unsafe public static void TestBytesGenerator(int maxLengthCh = 512 * 1024 * 1024, int iteration = 200) { RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(1024 * 1024); RandomBytesProducer.InitBytes(); //------- int maxLengthCh2 = (int)maxLengthCh << 1; Console.WriteLine("Test Bytes Generator :"); byte[] buffer = new byte[maxLengthCh]; GCHandle gchbuffers = GCHandle.Alloc(buffer, GCHandleType.Pinned); IntPtr addrBuffer = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, (int)maxLengthCh - 1); char * pBuffer = (char *)addrBuffer.ToPointer(); char * pCurrentBuffer = pBuffer; char * pBufferStart = (char *)Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0); string[] _templateCh = new string[10] { " apple" , " town" , " array" , " summer" , " winter" , " april" , " customer" , " support" , " laptop" , " cross-domain" }; byte[][] templateCh = DataProducer.ConvetStringListToBytes(_templateCh); int n = templateCh.Length; int[] sizes = new int[n]; GCHandle gchsizes = GCHandle.Alloc(sizes, GCHandleType.Pinned); IntPtr addrSizes = Marshal.UnsafeAddrOfPinnedArrayElement(sizes, 0); int * pSize = (int *)addrSizes.ToPointer(); int[] sizes2 = new int[n]; GCHandle gchsizes2 = GCHandle.Alloc(sizes2, GCHandleType.Pinned); IntPtr addrSizes2 = Marshal.UnsafeAddrOfPinnedArrayElement(sizes2, 0); int * pSizes2 = (int *)addrSizes2.ToPointer(); int sizeTmp = 0; for (int i = 0; i < n; i++) { sizeTmp = templateCh[i].Length; sizes[i] = sizeTmp; sizes2[i] = sizeTmp << 1; } int[] randomizeDictionary = new int[256 * 256]; int[] randomizeDictionarySize = new int[256 * 256]; int[] randomizeDictionarySize2 = new int[256 * 256]; int k = 0; for (int j = 0; j < 256 * 256; j++) { randomizeDictionary[j] = k; k++; if (k == n) { k = 0; } } k = 0; for (int j = 0; j < 256 * 256; j++) { randomizeDictionarySize[j] = (int)sizes[k]; k++; if (k == n) { k = 0; } } k = 0; for (int j = 0; j < 256 * 256; j++) { randomizeDictionarySize2[j] = (int)sizes2[k]; k++; if (k == n) { k = 0; } } dh.StartWatch(); int position = maxLengthCh; int templateLenghtCh = (int)templateCh.Length; int randomIndex = 0; byte[] endline = Encoding.ASCII.GetBytes(Environment.NewLine); GCHandle gchendline = GCHandle.Alloc(endline, GCHandleType.Pinned); byte[] dot = Encoding.ASCII.GetBytes("."); GCHandle gchdot = GCHandle.Alloc(endline, GCHandleType.Pinned); GCHandle gchrndInt = GCHandle.Alloc(endline, GCHandleType.Pinned); int minStrLength = 0; fixed(int *psize = randomizeDictionarySize, psize2 = randomizeDictionarySize2, pdic = randomizeDictionary) { for (int i = 0; i < iteration; i++) { position = maxLengthCh; AddEndLine(); while (position >= minStrLength) { if (AddNewLine(psize, psize2, pdic)) { AddNumber(); AddEndLine(); } } /* * if(position < 0) * { * pCurrentBuffer = pCurrentBuffer + templateLenghtCh - 1 ; * while(pCurrentBuffer >= pBufferStart) * { * pCurrentBuffer = '*'; * pCurrentBuffer--; * } * }*/ } } dh.StoptWatch(); templateCh = null; buffer = null; templateCh = null; sizes = null; sizes2 = null; if (gchrndInt.IsAllocated) { gchrndInt.Free(); } if (gchdot.IsAllocated) { gchdot.Free(); } if (gchendline.IsAllocated) { gchendline.Free(); } if (gchsizes2.IsAllocated) { gchsizes2.Free(); } if (gchsizes.IsAllocated) { gchsizes.Free(); } if (gchbuffers.IsAllocated) { gchbuffers.Free(); } GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); unsafe bool AddNewLine(int *psize, int *psize2, int *pdic) { randomIndex = rnd.Next16(); bool result = false; templateLenghtCh = *(psize + randomIndex); position -= templateLenghtCh; while (position >= minStrLength) { Buffer.BlockCopy(templateCh[*(pdic + randomIndex)], 0, buffer, position, templateLenghtCh); result = true; if (rnd.NextBool()) { templateLenghtCh = *(psize + randomIndex); position -= templateLenghtCh; } else { break; } } return(result); } bool AddEndLine() { if (position > 3) { position -= 2; Buffer.BlockCopy(endline, 0, buffer, position, 2); return(true); } return(false); } bool AddNumber() { int rndNumber = rnd.Next16(); byte[] strNumber = RandomBytesProducer.byteList[rndNumber]; int length = RandomBytesProducer.byteListSizes[rndNumber]; if (position > length) { position -= 1; Buffer.BlockCopy(dot, 0, buffer, position, 1); position -= length; Buffer.BlockCopy(strNumber, 0, buffer, position, length); return(true); } return(false); } } /* * { * int maxLengthCh = 512 * 1024 * 1024; * int maxLengthCh2 = maxLengthCh << 1; * Console.WriteLine("Test Bytes Generator :"); * char[] buffer = new char[maxLengthCh]; * * string[] templateCh = new string [10] * { * " apple" * , " town" * , " array" * , " summer" * , " winter" * , " april" * , " customer" * , " support" * , " laptop" * , " cross-domain" * }; * RandomIteratorUsafeXorshiftEn randomIteratorUsafeXorshiftEn = new RandomIteratorUsafeXorshiftEn(1024 * 1024); * RandomBytesProducer.InitBytes(); * * int n = templateCh.Length; * //GCHandle gchLines = GCHandle.Alloc(lines, GCHandleType.Pinned); * char*[] pLines = new char*[n]; * //GCHandle gchpLines = GCHandle.Alloc(pLines, GCHandleType.Pinned); * IntPtr[] linesPtr = new IntPtr[n]; * * int[] sizes = new int[n]; * GCHandle gchsizes = GCHandle.Alloc(sizes, GCHandleType.Pinned); * IntPtr addrSizes = Marshal.UnsafeAddrOfPinnedArrayElement(sizes, 0); * int* pSize = (int*)addrSizes.ToPointer(); * * int[] sizes2 = new int[n]; * GCHandle gchsizes2 = GCHandle.Alloc(sizes2, GCHandleType.Pinned); * IntPtr addrSizes2 = Marshal.UnsafeAddrOfPinnedArrayElement(sizes2, 0); * int* pSizes2 = (int*)addrSizes2.ToPointer(); * * int sizeTmp = 0; * for (int i = 0; i < n; i++) * { * sizeTmp = templateCh[i].Length; * sizes[i] = sizeTmp; * sizes2[i] = sizeTmp << 1; * } * dh.StartWatch(); * int position = maxLengthCh; * int position2 = maxLengthCh << 2; * int templateLenghtCh = templateCh.Length; * int templateLenghtCh2 = templateCh.Length << 1; * int randomIndex = 0; * n--;//-- * for (int i = 0; i < 200; i++) * { * randomIndex = n;//--rnd1.Next(n); * templateLenghtCh = *(pSize + randomIndex); * // * templateLenghtCh2 = *(pSizes2 + randomIndex); * //position = maxLengthCh - templateLenghtCh; * position2 = maxLengthCh2 - templateLenghtCh2; * while (position2 >= 0) * { * Buffer.BlockCopy(templateCh[randomIndex], 0, buffer, position2, templateLenghtCh2); * //Buffer.MemoryCopy(pLines[randomIndex], pCurrentBuffer, templateLenghtCh2, templateLenghtCh2); * //--randomIndex = rnd1.Next(n); * templateLenghtCh2 = *(pSizes2 + randomIndex); * //templateLenghtCh = *(pSize + randomIndex); * position2 -= templateLenghtCh2; * //position -= templateLenghtCh; * //pCurrentBuffer = pCurrentBuffer - templateLenghtCh; * } * //if(position2 < 0) * //{ * // pCurrentBuffer = pCurrentBuffer + templateLenghtCh - 1 ; * // while(pCurrentBuffer >= pBufferStart) * // { * // *pCurrentBuffer = '*'; * // pCurrentBuffer--; * // } * //} * } * dh.StoptWatch(); * templateCh = null; * buffer = null; * templateCh = null; * sizes = null; * sizes2 = null; * if (gchsizes2.IsAllocated) * { * gchsizes2.Free(); * } * * if (gchsizes.IsAllocated) * { * gchsizes.Free(); * } * GarbachCollectorHelper.GBForceRun(); * Console.WriteLine(dh.GetMessage()); * }*/ }
unsafe public static void TestBytesGeneratorStrongInline(int maxLengthCh = 512 * 1024 * 1024, int iteration = 200) { dh.StartWatch(); RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(1024 * 1024); RandomBytesProducer.InitBytes(); //------- int maxLengthCh2 = (int)maxLengthCh << 1; Console.WriteLine("Test Bytes Generator strong Inline :"); Console.WriteLine("Generating Data ..."); byte[] buffer = new byte[maxLengthCh]; GCHandle gchbuffers = GCHandle.Alloc(buffer, GCHandleType.Pinned); IntPtr addrBuffer = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, (int)maxLengthCh - 1); char * pBuffer = (char *)addrBuffer.ToPointer(); char * pCurrentBuffer = pBuffer; char * pBufferStart = (char *)Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0); string[] _templateCh = new string[10] { " apple" , " town" , " array" , " summer" , " winter" , " april" , " customer" , " support" , " laptop" , " cross-domain" }; byte[][] templateCh = DataProducer.ConvetStringListToBytes(_templateCh); int n = templateCh.Length; int[] sizes = new int[n]; GCHandle gchsizes = GCHandle.Alloc(sizes, GCHandleType.Pinned); IntPtr addrSizes = Marshal.UnsafeAddrOfPinnedArrayElement(sizes, 0); int * pSize = (int *)addrSizes.ToPointer(); int[] sizes2 = new int[n]; GCHandle gchsizes2 = GCHandle.Alloc(sizes2, GCHandleType.Pinned); IntPtr addrSizes2 = Marshal.UnsafeAddrOfPinnedArrayElement(sizes2, 0); int * pSizes2 = (int *)addrSizes2.ToPointer(); int sizeTmp = 0; for (int i = 0; i < n; i++) { sizeTmp = templateCh[i].Length; sizes[i] = sizeTmp; sizes2[i] = sizeTmp << 1; } int[] randomizeDictionary = new int[256 * 256]; int[] randomizeDictionarySize = new int[256 * 256]; int[] randomizeDictionarySize2 = new int[256 * 256]; int k = 0; for (int j = 0; j < 256 * 256; j++) { randomizeDictionary[j] = k; k++; if (k == n) { k = 0; } } k = 0; for (int j = 0; j < 256 * 256; j++) { randomizeDictionarySize[j] = (int)sizes[k]; k++; if (k == n) { k = 0; } } k = 0; for (int j = 0; j < 256 * 256; j++) { randomizeDictionarySize2[j] = (int)sizes2[k]; k++; if (k == n) { k = 0; } } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Executing ... "); dh.StartWatch(); int position = maxLengthCh; int templateLenghtCh = (int)templateCh.Length; int randomIndex = 0; byte[] endline = Encoding.ASCII.GetBytes(Environment.NewLine); GCHandle gchendline = GCHandle.Alloc(endline, GCHandleType.Pinned); byte[] dot = Encoding.ASCII.GetBytes("."); GCHandle gchdot = GCHandle.Alloc(endline, GCHandleType.Pinned); GCHandle gchrndInt = GCHandle.Alloc(endline, GCHandleType.Pinned); int minStrLength = 1 + 1 + 2 + sizes[0]; int numberLength = 0; int rndNumber = 0; bool AddedLine = false; fixed(int *psize = randomizeDictionarySize, psize2 = randomizeDictionarySize2, pdic = randomizeDictionary) { for (int i = 0; i < iteration; i++) { position = maxLengthCh; //AddEndLine(ref position, endline, buffer); while (position >= minStrLength) { //----------- AddedLine = false; if (position > 2) { --position; buffer[position] = 10; --position; buffer[position] = 13; } templateLenghtCh = *(psize + randomIndex); position -= templateLenghtCh; while (position >= minStrLength) { Buffer.BlockCopy(templateCh[*(pdic + randomIndex)], 0, buffer, position, templateLenghtCh); AddedLine = true; if (rnd.NextBool()) { templateLenghtCh = *(psize + randomIndex); position -= templateLenghtCh; } else { break; } } //----------- if (AddedLine) //if (AddNewLine(rnd.Next16(), ref templateLenghtCh, ref position, minStrLength, buffer, rnd, templateCh, psize, psize2, pdic)) { if (position > 0) { --position; buffer[position] = 46; } rndNumber = rnd.Next16(); numberLength = RandomBytesProducer.byteListSizes[rndNumber]; if (position > numberLength) { position -= numberLength; Buffer.BlockCopy(RandomBytesProducer.byteList[rndNumber], 0, buffer, position, numberLength); } //AddEndLine(ref position, endline, buffer); } } /* * if(position < 0) * { * pCurrentBuffer = pCurrentBuffer + templateLenghtCh - 1 ; * while(pCurrentBuffer >= pBufferStart) * { * pCurrentBuffer = '*'; * pCurrentBuffer--; * } * }*/ } } dh.StoptWatch(); templateCh = null; buffer = null; templateCh = null; sizes = null; sizes2 = null; if (gchrndInt.IsAllocated) { gchrndInt.Free(); } if (gchdot.IsAllocated) { gchdot.Free(); } if (gchendline.IsAllocated) { gchendline.Free(); } if (gchsizes2.IsAllocated) { gchsizes2.Free(); } if (gchsizes.IsAllocated) { gchsizes.Free(); } if (gchbuffers.IsAllocated) { gchbuffers.Free(); } GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); }
unsafe public static void TestArrayCopyFixed1(int iterationCount = 1) { Console.WriteLine("---------------------------------------------------------------"); Console.WriteLine("Copy array using pointer copy ++:"); Console.WriteLine("Generating data ... "); dh.StartWatch(); int n = 1024 * 1024 * 1024; RandomIteratorUsafeXorshiftEn rnd = new RandomIteratorUsafeXorshiftEn(1024 * 1024); rnd.Reset(); byte[] destArray = new byte[1024 * 1024 * 1024]; byte[] sourceArray = new byte[256]; Buffer.BlockCopy(rnd.values, 0, sourceArray, 0, 256); byte index = rnd.bNext(); byte *endDest = null; byte *endSrc = null; byte *currentSrc = null; byte *currentDest = null; dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); Console.WriteLine("Executing + ... "); dh.StartWatch(); for (int k = iterationCount; k != 0; --k) { endDest = null; currentSrc = null; currentDest = null; index = rnd.bNext(); fixed(byte *startDest = &destArray[0], startSource = &sourceArray[0]) { endDest = startDest + n - 1; endSrc = startSource + index; currentDest = startDest; do { currentSrc = startSource; endSrc = startSource + index; while (currentSrc <= endSrc) { *currentDest = *currentSrc; ++currentDest; ++currentSrc; } index = rnd.bNext(); }while ((currentDest + index) <= endDest); } } dh.StoptWatch(); Console.WriteLine(dh.GetMessage()); destArray = null; GarbachCollectorHelper.GBForceRun(); }
unsafe public static void TestArrayWithDictionaryPinnedArray() { int maxLengthCh = 512 * 1024 * 1024; int maxLengthCh2 = maxLengthCh << 1; Console.WriteLine("Test char array with dictionary :"); char[] buffer = new char[maxLengthCh]; GCHandle gchbuffers = GCHandle.Alloc(buffer, GCHandleType.Pinned); IntPtr addrBuffer = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, maxLengthCh - 1); char * pBuffer = (char *)addrBuffer.ToPointer(); char * pCurrentBuffer = pBuffer; char * pBufferStart = (char *)Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0); char[][] templateCh = { " apple".ToCharArray(), " town".ToCharArray(), " array".ToCharArray(), " summer".ToCharArray(), " winter".ToCharArray(), " april".ToCharArray(), " customer".ToCharArray(), " support".ToCharArray(), " laptop".ToCharArray(), " cross-domain".ToCharArray() }; int n = templateCh.Length; //GCHandle.Alloc(templateCh, GCHandleType.Pinned); GCHandle[] lines = new GCHandle[n]; //GCHandle gchLines = GCHandle.Alloc(lines, GCHandleType.Pinned); char *[] pLines = new char *[n]; //GCHandle gchpLines = GCHandle.Alloc(pLines, GCHandleType.Pinned); IntPtr[] linesPtr = new IntPtr[n]; //GCHandle gchlinesPtr = GCHandle.Alloc(linesPtr, GCHandleType.Pinned); for (int i = 0; i < n; i++) { lines[i] = GCHandle.Alloc(templateCh[i], GCHandleType.Pinned); linesPtr[i] = Marshal.UnsafeAddrOfPinnedArrayElement(templateCh[i], 0); pLines[i] = (char *)linesPtr[i].ToPointer(); } int[] sizes = new int[n]; GCHandle gchsizes = GCHandle.Alloc(sizes, GCHandleType.Pinned); IntPtr addrSizes = Marshal.UnsafeAddrOfPinnedArrayElement(sizes, 0); int * pSize = (int *)addrSizes.ToPointer(); int[] sizes2 = new int[n]; GCHandle gchsizes2 = GCHandle.Alloc(sizes2, GCHandleType.Pinned); IntPtr addrSizes2 = Marshal.UnsafeAddrOfPinnedArrayElement(sizes2, 0); int * pSizes2 = (int *)addrSizes2.ToPointer(); int sizeTmp = 0; for (int i = 0; i < n; i++) { sizeTmp = templateCh[i].Length; sizes[i] = sizeTmp; sizes2[i] = sizeTmp << 1; } dh.StartWatch(); int position = maxLengthCh; int position2 = maxLengthCh << 2; int templateLenghtCh = templateCh.Length; int templateLenghtCh2 = templateCh.Length << 1; int randomIndex = 0; n--;//-- for (int i = 0; i < 200; i++) { randomIndex = n;//--rnd1.Next(n); templateLenghtCh = *(pSize + randomIndex); // templateLenghtCh2 = *(pSizes2 + randomIndex); //position = maxLengthCh - templateLenghtCh; position2 = maxLengthCh2 - templateLenghtCh2; pCurrentBuffer = pBuffer - templateLenghtCh + 1; while (position2 >= 0) { Buffer.BlockCopy(templateCh[randomIndex], 0, buffer, position2, templateLenghtCh2); //Buffer.MemoryCopy(pLines[randomIndex], pCurrentBuffer, templateLenghtCh2, templateLenghtCh2); //--randomIndex = rnd1.Next(n); templateLenghtCh2 = *(pSizes2 + randomIndex); //templateLenghtCh = *(pSize + randomIndex); position2 -= templateLenghtCh2; //position -= templateLenghtCh; //pCurrentBuffer = pCurrentBuffer - templateLenghtCh; } /* * if(position2 < 0) * { * pCurrentBuffer = pCurrentBuffer + templateLenghtCh - 1 ; * while(pCurrentBuffer >= pBufferStart) * { * pCurrentBuffer = '*'; * pCurrentBuffer--; * } * }*/ } dh.StoptWatch(); templateCh = null; buffer = null; templateCh = null; sizes = null; sizes2 = null; if (gchsizes2.IsAllocated) { gchsizes2.Free(); } if (gchsizes.IsAllocated) { gchsizes.Free(); } if (gchbuffers.IsAllocated) { gchbuffers.Free();/* * if (gchLines.IsAllocated) * gchLines.Free();*//* * if (gchpLines.IsAllocated) * gchpLines.Free();*//* * if (gchlinesPtr.IsAllocated) * gchlinesPtr.Free();*/ } for (int i = 0; i < n; i++) { if (lines[i].IsAllocated) { lines[i].Free(); } } GarbachCollectorHelper.GBForceRun(); Console.WriteLine(dh.GetMessage()); }
unsafe public static void TestArrayWithDictionaryPinnedArrayFaterRandomIterator(int maxLengthCh = 512 * 1024 * 1024, int iteration = 200) { int maxLengthCh2 = (int)maxLengthCh << 1; Console.WriteLine("Test char array with dictionary and faster random iterator :"); char[] buffer = new char[maxLengthCh]; RandomIteratorUsafeXorshift rnd = new RandomIteratorUsafeXorshift(256); GCHandle gchbuffers = GCHandle.Alloc(buffer, GCHandleType.Pinned); IntPtr addrBuffer = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, (int)maxLengthCh - 1); char * pBuffer = (char *)addrBuffer.ToPointer(); char * pCurrentBuffer = pBuffer; char * pBufferStart = (char *)Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0); char[][] templateCh = { " apple".ToCharArray(), " town".ToCharArray(), " array".ToCharArray(), " summer".ToCharArray(), " winter".ToCharArray(), " april".ToCharArray(), " customer".ToCharArray(), " support".ToCharArray(), " laptop".ToCharArray(), " cross-domain".ToCharArray() }; int n = templateCh.Length; //GCHandle.Alloc(templateCh, GCHandleType.Pinned); GCHandle[] lines = new GCHandle[n]; //GCHandle gchLines = GCHandle.Alloc(lines, GCHandleType.Pinned); char *[] pLines = new char *[n]; //GCHandle gchpLines = GCHandle.Alloc(pLines, GCHandleType.Pinned); IntPtr[] linesPtr = new IntPtr[n]; //GCHandle gchlinesPtr = GCHandle.Alloc(linesPtr, GCHandleType.Pinned); for (int i = 0; i < n; i++) { lines[i] = GCHandle.Alloc(templateCh[i], GCHandleType.Pinned); linesPtr[i] = Marshal.UnsafeAddrOfPinnedArrayElement(templateCh[i], 0); pLines[i] = (char *)linesPtr[i].ToPointer(); } int[] sizes = new int[n]; GCHandle gchsizes = GCHandle.Alloc(sizes, GCHandleType.Pinned); IntPtr addrSizes = Marshal.UnsafeAddrOfPinnedArrayElement(sizes, 0); int * pSize = (int *)addrSizes.ToPointer(); int[] sizes2 = new int[n]; GCHandle gchsizes2 = GCHandle.Alloc(sizes2, GCHandleType.Pinned); IntPtr addrSizes2 = Marshal.UnsafeAddrOfPinnedArrayElement(sizes2, 0); int * pSizes2 = (int *)addrSizes2.ToPointer(); int sizeTmp = 0; for (int i = 0; i < n; i++) { sizeTmp = templateCh[i].Length; sizes[i] = sizeTmp; sizes2[i] = sizeTmp << 1; } int[] randomizeDictionary = new int[256 * 256]; int[] randomizeDictionarySize = new int[256 * 256]; int[] randomizeDictionarySize2 = new int[256 * 256]; int k = 0; for (int j = 0; j < 256 * 256; j++) { randomizeDictionary[j] = k; k++; if (k == n) { k = 0; } } k = 0; for (int j = 0; j < 256 * 256; j++) { randomizeDictionarySize[j] = (int)sizes[k]; k++; if (k == n) { k = 0; } } k = 0; for (int j = 0; j < 256 * 256; j++) { randomizeDictionarySize2[j] = (int)sizes2[k]; k++; if (k == n) { k = 0; } } //dh.StartWatch(); int position = maxLengthCh; int position2 = maxLengthCh << 2; int templateLenghtCh = (int)templateCh.Length; int templateLenghtCh2 = (int)templateCh.Length << 1; int randomIndex = 0; char[] endline = Environment.NewLine.ToCharArray(); GCHandle gchendline = GCHandle.Alloc(endline, GCHandleType.Pinned); char[] dot = new char[1] { '.' }; GCHandle gchdot = GCHandle.Alloc(endline, GCHandleType.Pinned); byte[] rndInt = new byte[4] { rnd.bNext(), rnd.bNext(), rnd.bNext(), rnd.bNext() }; GCHandle gchrndInt = GCHandle.Alloc(endline, GCHandleType.Pinned); byte rndIntIndex = 0; int minStrLength = 0; byte wordCount = 0; fixed(int *psize = randomizeDictionarySize, psize2 = randomizeDictionarySize2, pdic = randomizeDictionary) { for (int i = 0; i < iteration; i++) { position2 = maxLengthCh2; //position = maxLengthCh - templateLenghtCh; AddEndLine(); while (position2 >= minStrLength) { wordCount = (byte)((rnd.bNext() >> 5)); wordCount++; if (AddNewLine(psize, psize2, pdic, wordCount)) { AddNumber(); AddEndLine(); } } /* * if(position2 < 0) * { * pCurrentBuffer = pCurrentBuffer + templateLenghtCh - 1 ; * while(pCurrentBuffer >= pBufferStart) * { * pCurrentBuffer = '*'; * pCurrentBuffer--; * } * }*/ } } //dh.StoptWatch(); templateCh = null; buffer = null; templateCh = null; sizes = null; sizes2 = null; if (gchrndInt.IsAllocated) { gchrndInt.Free(); } if (gchdot.IsAllocated) { gchdot.Free(); } if (gchendline.IsAllocated) { gchendline.Free(); } if (gchsizes2.IsAllocated) { gchsizes2.Free(); } if (gchsizes.IsAllocated) { gchsizes.Free(); } if (gchbuffers.IsAllocated) { gchbuffers.Free();/* * if (gchLines.IsAllocated) * gchLines.Free();*//* * if (gchpLines.IsAllocated) * gchpLines.Free();*//* * if (gchlinesPtr.IsAllocated) * gchlinesPtr.Free();*/ } for (int i = 0; i < n; i++) { if (lines[i].IsAllocated) { lines[i].Free(); } } GarbachCollectorHelper.GBForceRun(); //Console.WriteLine(dh.GetMessage()); return; unsafe bool AddNewLine(int *psize, int *psize2, int *pdic, byte count) { byte counter = 0; randomIndex = (rnd.bNext() << 8) + rnd.bNext();//--rnd1.Next(n); // templateLenghtCh2 = *(psize2 + randomIndex); position2 -= templateLenghtCh2; while (position2 >= minStrLength) { Buffer.BlockCopy(templateCh[*(pdic + randomIndex)], 0, buffer, position2, templateLenghtCh2); counter++; if (counter >= count) { return(true); } else { templateLenghtCh2 = *(psize2 + randomIndex); position2 -= templateLenghtCh2; } } return(false); } bool AddEndLine() { if (position2 > 6) { position2 -= 4; Buffer.BlockCopy(endline, 0, buffer, position2, 4); return(true); } return(false); } /* * bool AddNumber() * { * uint rndNumber = BitConverter.ToUInt32(rndInt, 0); * if (rndNumber == 0) * { * rndNumber++; * } * byte shift = rnd.bNext(); * rndInt[rndIntIndex] = shift; * rndIntIndex++; * if(rndIntIndex>=4) * { * rndIntIndex = 0; * } * for(int i = 0; i < 4; i++) * { * rndInt[i] = (byte) (rndInt[i] & shift); * } * char[] strNumber = rndNumber.ToString().ToCharArray(); * int length2 = strNumber.Length << 1; * if (position2 > length2) * { * position2 -= 2; * Buffer.BlockCopy(dot, 0, buffer, position2, 2); * position2 -= length2; * Buffer.BlockCopy(strNumber, 0, buffer, position2, length2); * * return true; * } * * return false; * } */ bool AddNumber() { int rndNumber = rnd.Next(); ; char[] strNumber = rndNumber.ToString().ToCharArray(); int length2 = strNumber.Length << 1; if (position2 > length2) { position2 -= 2; Buffer.BlockCopy(dot, 0, buffer, position2, 2); position2 -= length2; Buffer.BlockCopy(strNumber, 0, buffer, position2, length2); return(true); } return(false); } } }