⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exarray_cpp.htm

📁 illustrate using std and stl libriry
💻 HTM
字号:
<html>



<head>

<meta http-equiv="Content-Type" content="text/html">

<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">

<title>exarray.cpp</title>

</head>



<body>



<pre>/*      exarray.cpp



        A template of dynamic arrays with automatic check of an index.

        Memory allocation funtions (minimal edition).



        (C) R.N.Shakirov, IMach of RAS (UB), 1998 - 2000

        All Rights Reserved.

/*

#include &lt;malloc.h&gt;

#include &lt;string.h&gt;

#include &lt;stdlib.h&gt;



//	Function exmrealloc allocates,

//	reallocates and frees zero filled

//	memory blocks.



void	exmrealloc (void **p, unsigned size, unsigned oldsize)

{

  if (size)			// Allocation.

  {

    if (size &gt; (~0u)-9)

      abort();			// Size range error



    if ((*p = realloc (*p, size))==NULL)

      abort();			// Allocation error



    if (size &gt; oldsize)	// Zero filling

      memset ((char*)*p+oldsize, 0, size-oldsize);

  }

  else				// Freeing.

  {

    if (*p) { free (*p); *p = NULL; }

  }

}



//	Function excalcsize computes size of

//	memory block (in bytes) not less then requred.

//	For this purpose SIZE_MOD multiplies by 2 and 1.5.

//	On unsigned int overflow excalcsize returns ~0u.

//	For less fragmentation the system header size

//	SIZE_SYS is taken into account.

//	For L1 Pentuim cache optimization SIZE_MOD

//	sets as 64**n +/- 16.



#define SIZE_MOD (112)

#define SIZE_SYS (sizeof(int) * 2)



unsigned excalcsize (unsigned size)

{

  unsigned n = SIZE_MOD, k = 0;

  for (;; k = ~k,

	(k? (n &lt;&lt;= 1): (n += (n &gt;&gt; 1))))

  {

    n -= SIZE_SYS; if (n  &gt;= size) break;

    n += SIZE_SYS; if ((int)n &lt; 0) { n =~0u; break; }

  }

  return (n);

}</pre>

</body>

</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -