반응형
//********************************************************
// 동적 배열  
//*******************************************************
// 1) C언어 !! 
// --> malloc, calloc , realloc 
//********************************************************
//********************************************************
#include 
#include  
void printArray( int * buf )
{
	for(int i = 0; i< _msize(buf)/sizeof(int) ; i++)
	{
		printf("%d", *(buf+i));
	}
	puts("");
}
void main()
{
	// malloc --> heap메모리에 내가 원하는 만큼의 메모리 공간을 할당하고
	// 공간의 시작 주소값을 리턴해주는 함수 !! 
	//int * buf  = (int*)malloc( sizeof( int) * 10 );
	//  malloc + memset  
//	int * buf  =  (int*)calloc( 10, sizeof(int));
	// _msize : heap에 할당된 메모리의 크기 
	/*
	printf("buf : %d\n" ,  _msize( buf));
	printArray( buf);
	buf  = (int*)realloc(buf, _msize(buf)*2); 
	printArray( buf);
	printf("buf : %d\n" ,  _msize( buf));

	free( buf); 
	*/ 
	 int * buf = new int[10]; 

	 printf("buf : %d\n" ,  _msize( buf));

	 // 메모리 해제 !! 
	 delete [] buf; 


}

+ Recent posts