コード例 #1
0
        /// <summary>
        /// Get a row size
        /// </summary>
        public static long GetRowSizeFromDataRow(DmRow row)
        {
            bool isRowDeleted = false;

            if (row.RowState == DmRowState.Deleted)
            {
                row.RejectChanges();
                isRowDeleted = true;
            }

            long byteCount = 0;

            object[] itemArray = row.ItemArray;

            for (int i = 0; i < itemArray.Length; i++)
            {
                // Size for the value
                object obj     = itemArray[i];
                Type   objType = obj != null?obj.GetType() : null;


                if (obj == null)
                {
                    byteCount = byteCount + 5;
                }
                else if (obj is DBNull)
                {
                    byteCount = byteCount + 5;
                }
                else if (objType == stringType)
                {
                    byteCount = byteCount + Encoding.UTF8.GetByteCount((string)obj);
                }
                else if (objType == byteArrayType)
                {
                    byteCount = byteCount + ((byte[])obj).Length;
                }
                else
                {
                    byteCount = byteCount + GetSizeForType(obj.GetType());
                }

                // Size for the type
                var typeofobject    = row.Table.Columns[i].DataType;
                var byteslengthtype = Encoding.UTF8.GetBytes(DmUtils.GetAssemblyQualifiedName(typeofobject)).Length;
                byteCount += byteslengthtype;

                // State
                byteCount += 4L;

                // Index
                byteCount += 4L;
            }
            if (isRowDeleted)
            {
                row.Delete();
            }
            return(byteCount);
        }
コード例 #2
0
        /// <summary>
        /// Calculate an estimation of the dictionary values size
        /// </summary>
        public static long GetRowSizeFromDataRow(object[] itemArray)
        {
            long byteCount = 0;

            foreach (var obj in itemArray)
            {
                var objType = obj?.GetType();

                if (obj == null)
                {
                    byteCount += 5;
                }
                else if (obj is DBNull)
                {
                    byteCount += 5;
                }
                else if (objType == stringType)
                {
                    byteCount += Encoding.UTF8.GetByteCount((string)obj);
                }
                else if (objType == byteArrayType)
                {
                    byteCount += ((byte[])obj).Length;
                }
                else
                {
                    byteCount += GetSizeForType(obj.GetType());
                }

                // Size for the type
                if (objType != null)
                {
                    byteCount += Encoding.UTF8.GetBytes(DmUtils.GetAssemblyQualifiedName(objType)).Length;
                }

                // State
                byteCount += 4L;

                // Index
                byteCount += 4L;
            }
            return(byteCount);
        }