'프로그래밍 > Windows API' 카테고리의 다른 글
GetLastError() / FormatMessage() 함수 사용 샘플 코드 (0) | 2012.12.18 |
---|---|
윈도우 메모리 - 4 (힙과 메모리 맵) (0) | 2011.03.12 |
윈도우 메모리 - 3 (VirtualAlloc) (0) | 2011.03.11 |
윈도우 메모리 - 2 (malloc 함수) (2) | 2011.03.11 |
윈도우 메모리 - 1 (0) | 2011.03.10 |
GetLastError() / FormatMessage() 함수 사용 샘플 코드 (0) | 2012.12.18 |
---|---|
윈도우 메모리 - 4 (힙과 메모리 맵) (0) | 2011.03.12 |
윈도우 메모리 - 3 (VirtualAlloc) (0) | 2011.03.11 |
윈도우 메모리 - 2 (malloc 함수) (2) | 2011.03.11 |
윈도우 메모리 - 1 (0) | 2011.03.10 |
ptrHeap = HeapAlloc(GetProcessHeap(), 0, sizeof(int)); HeapFree(GetProcessHealp, 0, ptrHeap);
GetLastError() / FormatMessage() 함수 사용 샘플 코드 (0) | 2012.12.18 |
---|---|
윈도우 메모리 파이널! (0) | 2011.03.12 |
윈도우 메모리 - 3 (VirtualAlloc) (0) | 2011.03.11 |
윈도우 메모리 - 2 (malloc 함수) (2) | 2011.03.11 |
윈도우 메모리 - 1 (0) | 2011.03.10 |
LPVOID WINAPI VirtualAlloc( __in_opt LPVOID lpAddress, __in SIZE_T dwSize, __in DWORD flAllocationType, __in DWORD flProtect );
Value | Meaning |
---|---|
|
Allocates physical storage in memory or in the paging file on disk for the specified reserved memory pages. The function initializes the memory to zero. To reserve and commit pages in one step, call VirtualAlloc with MEM_COMMIT | MEM_RESERVE. The function fails if you attempt to commit a page that has not been reserved. The resulting error code is ERROR_INVALID_ADDRESS. An attempt to commit a page that is already committed does not cause the function to fail. This means that you can commit pages without first determining the current commitment state of each page. |
|
Reserves a range of the process's virtual address space without allocating any actual physical storage in memory or in the paging file on disk. You can commit reserved pages in subsequent calls to the VirtualAlloc function. To reserve and commit pages in one step, call VirtualAlloc with MEM_COMMIT | MEM_RESERVE. Other memory allocation functions, such as malloc and LocalAlloc, cannot use a reserved range of memory until it is released. |
|
Indicates that data in the memory range specified by lpAddress and dwSize is no longer of interest. The pages should not be read from or written to the paging file. However, the memory block will be used again later, so it should not be decommitted. This value cannot be used with any other value. Using this value does not guarantee that the range operated on with MEM_RESET will contain zeroes. If you want the range to contain zeroes, decommit the memory and then recommit it. When you specify MEM_RESET, the VirtualAlloc function ignores the value offlProtect. However, you must still set flProtect to a valid protection value, such as PAGE_NOACCESS. VirtualAlloc returns an error if you use MEM_RESET and the range of memory is mapped to a file. A shared view is only acceptable if it is mapped to a paging file. |
간단한 예를 보면,
ptr = (int *)VirtualAlloc(NULL, sizeof(int)*10, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); VirtualFree(ptr, sizeof(int)*10,MEM_DECOMMIT); VirtualFree(ptr, 0, MEM_RELEASE);VirtualFree에 대한 설명이 빠졌는데 메모리 해제 함수다. MEM_DECOMMIT은 확정 해제, MEM_RELEASE는 예약 해제다. 메모리 할당도 MEM_RESERVE와 MEM_COMMIT를 같이 불러 호출하거나 따로 각각 두번 호출해야 한다. malloc보다 좀 번거롭긴 하다.
윈도우 메모리 파이널! (0) | 2011.03.12 |
---|---|
윈도우 메모리 - 4 (힙과 메모리 맵) (0) | 2011.03.12 |
윈도우 메모리 - 2 (malloc 함수) (2) | 2011.03.11 |
윈도우 메모리 - 1 (0) | 2011.03.10 |
윈도우 - 차일드, 팝업 (0) | 2009.11.17 |
1: #include <stdio.h>
2: #include <stdlib.h>
3: #include <string.h>
4:
5: #ifdef _DEBUG
6: #include <vld.h>
7: #include <vldapi.h>
8: #endif
9:
10: void main()
11: {
12: // Test int
13: int *ptr;
14: ptr = (int*)malloc(sizeof(int)*10);
15:
16: for(int i = 0; i < 10; i++)
17: {
18: ptr[i] = i * 10;
19: printf("ptr[%d] = %d\n", i, ptr[i]);
20: }
21:
22: free(ptr);
23:
24: // Test char
25: char *ptr_char;
26: ptr_char = (char *)malloc(sizeof(char)*20);
27:
28: char *str1 = "MEMORY LEAK";
29: strcpy(ptr_char, str1);
30:
31: printf("ptr_char = %s\n", ptr_char);
32:
33: free(ptr_char);
34:
35: // Test array of pointers
36: int **double_ptr;
37:
38: double_ptr = (int **)malloc(sizeof(int *)*10);
39:
40: for(int i = 0; i < 10; i++)
41: {
42: double_ptr[i] = (int *)malloc(sizeof(int)*10);
43: for(int j = 0; j < 10; j++)
44: {
45: double_ptr[i][j] = (i * 10) + j;
46: printf("double_ptr[%d][%d] = %d\n", i, j, double_ptr[i][j]);
47: }
48: }
49:
50: for(int i = 0; i < 10; i++)
51: {
52: free(double_ptr[i]);
53: }
54:
55: free(double_ptr);
56:
57: }
윈도우 메모리 - 4 (힙과 메모리 맵) (0) | 2011.03.12 |
---|---|
윈도우 메모리 - 3 (VirtualAlloc) (0) | 2011.03.11 |
윈도우 메모리 - 1 (0) | 2011.03.10 |
윈도우 - 차일드, 팝업 (0) | 2009.11.17 |
윈도우 - SetClassLongPtr(), SetWindowLongPtr() (0) | 2009.11.17 |
윈도우 메모리 - 3 (VirtualAlloc) (0) | 2011.03.11 |
---|---|
윈도우 메모리 - 2 (malloc 함수) (2) | 2011.03.11 |
윈도우 - 차일드, 팝업 (0) | 2009.11.17 |
윈도우 - SetClassLongPtr(), SetWindowLongPtr() (0) | 2009.11.17 |
윈도우 - WNDCLASS 구조체 (0) | 2009.11.17 |
What is the most resilient parasite?
- 가장 생명력이 강한 기생충이 무엇인가?
A bacteria? A virus?
- 박테리아? 바이러스?
An intestinal worm?
- 장에 기생하는 벌레?
Uh...
- 음...
What Mr. Cobb is trying to say-
- Mr. Cobb 씨가 하려는 말은,
An idea.
- '생각' 입니다.
Resilient. Highly contagious.
- 질기고 매우 전염성이 강하죠.
Once an idea has taken hold of the brain, it's almost impossible
to eradicate.
- 한번 머리속에 자리를 잡은 하나의 생각은 제거하는 것이 거의 불가능에 가깝습니다.
An idea that is fully formed, fully understood, that sticks.
- 완전히 형성되고 완전히 이해되버린 달라 붙은 생각.
Right in there somewhere.
- 바로 거기 어딘가.
C run-time
library |
Associated DLL |
Characteristics |
Option |
Preprocessor
directives |
libcmt.lib |
None, static
link. |
Multithreaded,
static link |
_MT |
|
msvcrt.lib |
msvcr80.dll |
Multithreaded,
dynamic link (import library for MSVCR80.DLL). Be aware that if you use the
Standard C++ Library, your program will need MSVCP80.DLL to run. |
_MT, _DLL |
|
libcmtd.lib |
None, static link |
Multithreaded,
static link (debug) |
/MTd |
_DEBUG, _MT |
msvcrtd.lib |
msvcr80d.dll |
Multithreaded,
dynamic link (import library for MSVCR80D.DLL) (debug). |
/MDd |
_DEBUG, _MT, _DLL |
msvcmrt.lib |
msvcm80.dll |
C Runtime import
library. Used for mixed managed/native code. |
/clr |
|
msvcurt.lib |
msvcm80.dll |
C Runtime import
library compiled as 100% pure MSIL code. All code complies with the ECMA URT
spec for MSIL. |
/clr:pure |
|
헌데 재미 있는 것은 Visual C++는 추가적으로 헤더의 선언 유무에 따라 Standard C++ library도 링크한다는 것이다. 자, 여기서 조금 헷갈리는데 위의 테이블은 분명 Visual C++의 프로젝트 옵션의 컴파일 설정에 따라 링크하는 라이브러리가 결정되었다. 헌데 아래 테이블에 나오는 라이브러리는 단순히 프로젝트 옵션의 컴파일 설정에 의해 결정되는 것이 아니라 Standard C++ library header가 프로그램에 포함되었는지를 보고 링크가 이루어 진다.
Standard C++
Library |
Characteristics |
Option |
Preprocessor
directives |
LIBCPMT.LIB |
Multithreaded,
static link |
/MT |
_MT |
MSVCPRT.LIB |
Multithreaded,
dynamic link (import library for MSVCP80.dll) |
/MD |
_MT, _DLL |
LIBCPMTD.LIB |
Multithreaded,
static link |
/MTd |
_DEBUG, _MT |
MSVCPRTD.LIB |
Multithreaded,
dynamic link (import library for MSVCP80D.DLL) |
/MDd |
_DEBUG, _MT, _DLL |
바로 요 아래에 있는 것이 Standard C++ library header 파일들의 목록이다. 바로 요놈들중에 한놈이라도 프로그램에 선언되어 사용되는 놈이 있다면 위의 테이블에 나온놈들중에서 현재 프로젝트의 컴파일 옵션에 따라 적당한 라이브러리가 추가로 링크가된다.
|
In addition, the
following C++ wrappers are documented:
그렇다면 만약 ctime 부분을 포함시키면 어떻게 될까? ctime은 Standard C++ library header 중의 하나이기 때문에 현재 컴파일 설정인 /MDd에 해당하는 라이브러리인 MSVCPRTD.lib가 포함될까? 정답은 아래 그림속에...
앞서본 그림과 달리 아래 부분에 msvcprtd.lib가 포함되어 있다! 호~이!
Name | From | Description |
---|---|---|
<assert.h> |
Contains the assert macro, used to assist with detecting logical errors and other types of bug in debugging versions of a program. | |
<complex.h> |
C99 | A set of functions for manipulating complex numbers. |
<ctype.h> |
Contains functions used to classify characters by their types or to convert between upper and lower case in a way that is independent of the used character set (typically ASCII or one of its extensions, although implementations utilizing EBCDIC are also known). | |
<errno.h> |
For testing error codes reported by library functions. | |
<fenv.h> |
C99 | For controlling floating-point environment. |
<float.h> |
Contains defined constants specifying the implementation-specific properties of the floating-point library, such as the minimum difference between two different floating-point numbers (_EPSILON ), the maximum number of digits of accuracy (_DIG ) and the range of numbers which can be represented (_MIN , _MAX ). |
|
<inttypes.h> |
C99 | For precise conversion between integer types. |
<iso646.h> |
NA1 | For programming in ISO 646 variant character sets. |
<limits.h> |
Contains defined constants specifying the implementation-specific properties of the integer types, such as the range of numbers which can be represented (_MIN , _MAX ). |
|
<locale.h> |
For setlocale and related constants. This is used to choose an appropriate locale. |
|
<math.h> |
For computing common mathematical functions. | |
<setjmp.h> |
Declares the macros setjmp and longjmp , which are used for non-local exits. |
|
<signal.h> |
For controlling various exceptional conditions. | |
<stdarg.h> |
For accessing a varying number of arguments passed to functions. | |
<stdbool.h> |
C99 | For a boolean data type. |
<stdint.h> |
C99 | For defining various integer types. |
<stddef.h> |
For defining several useful types and macros. | |
<stdio.h> |
Provides the core input and output capabilities of the C language. This file includes the venerable printf function. |
|
<stdlib.h> |
For performing a variety of operations, including conversion, pseudo-random numbers, memory allocation, process control, environment, signalling, searching, and sorting. | |
<string.h> |
For manipulating several kinds of strings. | |
<tgmath.h> |
C99 | For type-generic mathematical functions. |
<time.h> |
For converting between various time and date formats. | |
<wchar.h> |
NA1 | For manipulating wide streams and several kinds of strings using wide characters - key to supporting a range of languages. |
<wctype.h> |
NA1 | For classifying wide characters. |
C Language Constructors and Destructors with GCC (0) | 2015.02.12 |
---|---|
싱글 스레드에서 멀티 스레드로... 왜 /MD 인가? (0) | 2010.03.11 |
호출 규약 (0) | 2009.07.28 |
커널 오브젝트 (Kernel Objects) (0) | 2012.12.13 |
---|---|
Understanding InvokeRequired() 함수 (0) | 2012.12.13 |
USB로 윈도우 XP 설치하기 (4) | 2010.07.01 |
프로그램의 원리 (컴파일, 링크, DLL) (0) | 2010.03.11 |
유니코드 (Updated!) (4) | 2010.03.06 |