virtual v. physical memory in assessing C/C++ memory leak -
i have c++ application trying iron memory leaks out of , realized don't understand difference between virtual , physical memory.
results top (so 16.8g = virtual, 111m = physical):
4406 um 20 0 16.8g 111m 4928 s 64.7 22.8 36:53.65 client
my process holds 500 connections, 1 each user, , @ these numbers means there 30 mb of virtual overhead each user. without going details of application, way sound remotely realistic, adding vectors, structs, threads, functions on stack, etc., if have no idea virtual memory means. no -o optimization flags, btw.
so questions are:
- what operations in c++ inflate virtual memory much?
- is problem if task using gigs of virtual memory?
- the stack , heap function variables, vectors, etc. - increase use of physical memory?
- would removing memory leak (via
deleteorfree()or such) reduce both physical , virtual memory usage?
virtual memory program deals with. consists of of addresses returned malloc, new, et al. each process has own virtual-address space. virtual address usage theoretically limited address size of program: 32-bit programs have 4gb of address space; 64-bit programs have vastly more. practically speaking, amount of virtual memory process can allocate less limits.
physical memory chips soldered motherboard, or installed in memory slots. amount of physical memory in use @ given time limited amount of physical memory in computer.
the virtual-memory subsystem maps virtual addresses program uses physical addresses cpu sends ram chips. @ particular moment, of allocated virtual addresses unmapped; physical memory use lower virtual memory use. if access virtual address allocated not mapped, operating system invisibly allocates physical memory , maps in. when don't access virtual address, operating system might unmap physical memory.
to take questions in turn:
- what operations in c++ inflate virtual memory much?
new, malloc, static allocation of large arrays. requires memory in program.
- is problem if task using gigs of virtual memory?
it depends upon usage pattern of program. if allocate vast tracks of memory never, ever touch, , if program 64-bit program, may okay using gigs of virtual memory.
also, if memory use grows without bound, run out of resource.
- the stack , heap function variables, vectors, etc. - increase use of physical memory?
not necessarily, likely. act of touching variable ensures that, @ least momentarily, (and of memory "near" it) in physical memory. (aside: containers std::vector may allocated on either stack or heap, contained objects allocated on heap.)
- would removing memory leak (via delete or free() or such) reduce both physical , virtual memory usage?
physical: probably. virtual: yes.
Comments
Post a Comment