VC的效率比BCB底很多啊,大家看这个测试程序:
// memtest1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
typedef struct _list
{
char buf[102400];
_list *next;
}myList;
typedef struct
{
char buf[102400];
}data;
void freelist(myList *p)
{
myList *head,*tmp;
head=p;
while(head)
{
tmp=head->next;
delete head;
head=tmp;
}
}
void mFree(void **p)
{
if ( *p != (void*)NULL)
free( *p );
(*p) = (void*)NULL;
return;
}
void GetData(data **p,int size)
{
*p=(data *)calloc(size,sizeof(data));
}
int main(int argc, char* argv[])
{
printf("Hello World!\n");
myList *Head=NULL,*p=NULL,*q=NULL;
int t1=0,t2=0,t=0;
t1=GetTickCount();
Head=NULL;
for(int i=0;i<2000;i++)
{
p=new myList;
memset(p->buf,0,102400);
if(Head==NULL)
Head=p;
else
q->next=p;
q=p;
}
q->next=NULL;
freelist(Head);
t2=GetTickCount();
t=t2-t1;
data *a;
t1=GetTickCount();
GetData(&a,2000);
mFree((void **)&a);
t2=GetTickCount();
t=t2-t1;
return 0;
}
大家把这个程序直接放到BCB中也可以运行,比较一下t的数值,二个内存分配的方法在VC中都比BCB慢,
而且BCB的一次性分配快,链表慢,但是VC是链表快.