Esempio n. 1
0
        private void testN3(SourceTask task)
        {
            for (int cst = 1; cst < 11 && cst < task.Size; cst++)
            {
                using (var bbs = new BytesBuilderStatic(task.Size))
                {
                    var bbp = new BytesBuilderForPointers();
                    var bbb = new BytesBuilder();

                    var allocator = new BytesBuilderForPointers.AllocHGlobal_AllocatorForUnsafeMemory();
                    var fix       = new BytesBuilderForPointers.Fixed_AllocatorForUnsafeMemory();
                    int size      = task.Size;
                    {
                        BytesBuilderForPointers.Record res_bbs = null, res_bbp = null, res_bbb = null;
                        try
                        {
                            try
                            {
                                byte V = 1;
                                var  r = allocator.AllocMemory(size - 1);
                                // var  r2 = allocator.AllocMemory(size >> 1);
                                while (bbb.Count < size - 1)
                                {
                                    for (int i = 0; i < r.len; i++)
                                    {
                                        r.array[i] = V++;
                                    }

                                    bbs.add(r);
                                    bbp.addWithCopy(r, r.len, allocator);
                                    for (int i = 0; i < r.len; i++)
                                    {
                                        bbb.addByte(r.array[i]);
                                    }
                                }
                                bbs.add(r.array, 1);
                                bbp.addWithCopy(r.array, 1, allocator);
                                bbb.addByte(r.array[0]);

                                r.Dispose();
                                r = null;

                                int remainder = size;
                                do
                                {
                                    remainder -= cst;

                                    try
                                    {
                                        res_bbs = allocator.AllocMemory(cst);
                                        bbs.getBytesAndRemoveIt(res_bbs);
                                        if (bbs.Count != remainder)
                                        {
                                            throw new Exception("Test_BytesBuilder.testN: size = " + task.Size + ", bbs.Count > 1: " + bbs.Count);
                                        }

                                        res_bbp = allocator.AllocMemory(cst);
                                        bbp.getBytesAndRemoveIt(res_bbp);
                                        if (bbp.Count != remainder)
                                        {
                                            throw new Exception("Test_BytesBuilder.testN: size = " + task.Size + ", bbp.Count > 1: " + bbp.Count);
                                        }

                                        res_bbb = fix.FixMemory(bbb.getBytesAndRemoveIt(resultCount: cst));
                                        if (bbb.Count != remainder)
                                        {
                                            throw new Exception("Test_BytesBuilder.testN: size = " + task.Size + ", bbb.Count > 1: " + bbb.Count);
                                        }

                                        if (!BytesBuilderForPointers.isArrayEqual_Secure(res_bbs, res_bbp) || !BytesBuilderForPointers.isArrayEqual_Secure(res_bbs, res_bbb))
                                        {
                                            throw new Exception("Test_BytesBuilder.testN: size = " + task.Size + " unequal");
                                        }
                                    }
                                    finally
                                    {
                                        res_bbs?.Dispose();
                                        res_bbp?.Dispose();
                                        res_bbb?.Dispose();
                                        res_bbs = null;
                                        res_bbp = null;
                                        res_bbb = null;
                                    }

                                    try
                                    {
                                        res_bbs = bbs.getBytes();
                                        res_bbp = bbp.getBytes();
                                        res_bbb = fix.FixMemory(bbb.getBytes());

                                        if (!BytesBuilderForPointers.isArrayEqual_Secure(res_bbs, res_bbp) || !BytesBuilderForPointers.isArrayEqual_Secure(res_bbs, res_bbb))
                                        {
                                            throw new Exception("Test_BytesBuilder.testN: size = " + task.Size + " unequal [2]");
                                        }
                                    }
                                    finally
                                    {
                                        res_bbs?.Dispose();
                                        res_bbp?.Dispose();
                                        res_bbb?.Dispose();
                                        res_bbs = null;
                                        res_bbp = null;
                                        res_bbb = null;
                                    }
                                }while (bbs.Count > cst);
                            }
                            finally
                            {
                                bbs.Clear();
                                bbp.Clear();
                                bbb.Clear();
                            }
                        }
                        finally
                        {
                            res_bbs?.Dispose();
                            res_bbp?.Dispose();
                            res_bbb?.Dispose();
                            res_bbs = null;
                            res_bbp = null;
                            res_bbb = null;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void testN1(SourceTask task)
        {
            using (var bbs = new BytesBuilderStatic(task.Size))
            {
                var bbp = new BytesBuilderForPointers();
                var bbb = new BytesBuilder();

                var allocator = new BytesBuilderForPointers.AllocHGlobal_AllocatorForUnsafeMemory();
                var fix       = new BytesBuilderForPointers.Fixed_AllocatorForUnsafeMemory();
                for (int size = 1; size <= task.Size; size++)
                {
                    BytesBuilderForPointers.Record res_bbs = null, res_bbb = null, res_bbp = null, res_bbs2 = null, r = null;

                    try
                    {
                        try
                        {
                            byte V = 1;
                            r = allocator.AllocMemory(size);
                            while (bbb.Count + size <= size)
                            {
                                for (int i = 0; i < r.len; i++)
                                {
                                    r.array[i] = V++;
                                }

                                bbs.add(r);
                                bbp.addWithCopy(r, r.len, allocator);
                                for (int i = 0; i < r.len; i++)
                                {
                                    bbb.addByte(r.array[i]);
                                }
                            }
                            r.Dispose();

                            res_bbs = bbs.getBytes();
                            res_bbp = bbp.getBytes();
                            res_bbb = fix.FixMemory(bbb.getBytes());

                            bbs.Resize(bbs.size + 1);
                            res_bbs2 = bbs.getBytes();
                        }
                        finally
                        {
                            bbs.Clear();
                            bbp.Clear();
                            bbb.Clear();
                        }

                        if (!BytesBuilderForPointers.isArrayEqual_Secure(res_bbs, res_bbp) || !BytesBuilderForPointers.isArrayEqual_Secure(res_bbs, res_bbb) || !BytesBuilderForPointers.isArrayEqual_Secure(res_bbs2, res_bbb))
                        {
                            throw new Exception("Test_BytesBuilder.testN: size = " + task.Size + " unequal");
                        }
                    }
                    finally
                    {
                        res_bbs?.Dispose();
                        res_bbp?.Dispose();
                        res_bbb?.Dispose();
                        res_bbs2?.Dispose();
                    }
                }
            }
        }