Click here to Skip to main content
15,889,216 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: combobox Pin
Ahmed_Barakat30-Jan-06 17:31
Ahmed_Barakat30-Jan-06 17:31 
GeneralRe: combobox Pin
Stephen Hewitt30-Jan-06 17:43
Stephen Hewitt30-Jan-06 17:43 
GeneralRe: combobox Pin
Owner drawn30-Jan-06 17:43
Owner drawn30-Jan-06 17:43 
GeneralRe: combobox Pin
Stephen Hewitt30-Jan-06 17:50
Stephen Hewitt30-Jan-06 17:50 
AnswerRe: combobox Pin
Christian Graus30-Jan-06 15:30
protectorChristian Graus30-Jan-06 15:30 
QuestionFiguring out the name of the Administrators group Pin
A_L30-Jan-06 12:27
A_L30-Jan-06 12:27 
AnswerRe: Figuring out the name of the Administrators group Pin
Michael Dunn30-Jan-06 13:24
sitebuilderMichael Dunn30-Jan-06 13:24 
QuestionVirtualAlloc question ? Pin
devboycpp30-Jan-06 11:26
devboycpp30-Jan-06 11:26 
Assuming that I know my program will not need to dynamically allocate more than 5 pages of memory(5*4096),Can I use this function for my memory allocations ?This function gets a pointer,number of bytes requested and returns the address of memory(in p).If failed returns 0.
The first time this function is called it reserves 5 pages of memory and saves its start address in "bm" variable.and commites one page of those pages."l" variable acts as a counter(accumulator) that ranges from 0 to 4096(one page size);I used this to to decide when to commite a new page.(when the size requested by the "size" parameter plus "l" exceeds 4096)and to return the next address to the caller(p=(char*)m+l)."m" variable is start address of the commited page.Memory is returned in the "p" parameter.
In short this function commites 1 page ,returns requested addresses from that page until reaches the end of the page where it commites another page.
According to my assumption can using this function cause trouble in my application or not.
I tested this function for allocating int ,double,string data types and struct and this worked.I mean I could write to the returned address and read the written values.I would have used "npr" and "npc" variables to keep the count of reserved and comitted pages respectively but accoring to my assumption I found them useless.
Please evaluate the function and tell me the probable problems that you think can occure when used.Or any suggestion ,experience you may have .Guide me
(consider my assumption)
int mem(void* &p,int size)
{
	static void * m=0;
	static void * bm=0;
	static int l=0;
	static int npr=5;
	static int npc=0;
	if(bm==0)
	{
		bm=m=VirtualAlloc(0,5*4096,MEM_RESERVE,PAGE_READWRITE);
		if(m==0)
			return 0;
		m=VirtualAlloc(m,4096,MEM_COMMIT,PAGE_READWRITE);
	}
if(size+l>=4096)
{

	if((m=VirtualAlloc((char*)m+4096,4096,MEM_COMMIT,PAGE_READWRITE))!=0)
	{
		l=0;
		l+=size;
		p=m;
	}
	else
		return 0;
}
else
{
        p=(char*)m+l;
	l+=size;
}
}


-- modified at 17:26 Monday 30th January, 2006
AnswerRe: VirtualAlloc question ? Pin
Michael Dunn30-Jan-06 12:19
sitebuilderMichael Dunn30-Jan-06 12:19 
GeneralRe: VirtualAlloc question ? Pin
devboycpp31-Jan-06 11:45
devboycpp31-Jan-06 11:45 
AnswerRe: VirtualAlloc question ? Pin
Sumit Kapoor30-Jan-06 14:23
Sumit Kapoor30-Jan-06 14:23 
GeneralRe: VirtualAlloc question ? Pin
devboycpp31-Jan-06 12:18
devboycpp31-Jan-06 12:18 
QuestionAcquiring resource information for a device - Windows XP Pin
Dethulus30-Jan-06 9:18
Dethulus30-Jan-06 9:18 
AnswerRe: Acquiring resource information for a device - Windows XP Pin
Toby Opferman30-Jan-06 11:16
Toby Opferman30-Jan-06 11:16 
GeneralRe: Acquiring resource information for a device - Windows XP Pin
Dethulus30-Jan-06 12:19
Dethulus30-Jan-06 12:19 
NewsRe: Acquiring resource information for a device - Windows XP Pin
Dethulus31-Jan-06 4:30
Dethulus31-Jan-06 4:30 
QuestionVisual C++ 2005 Pin
masnu30-Jan-06 8:54
masnu30-Jan-06 8:54 
AnswerRe: Visual C++ 2005 Pin
Rob Caldecott30-Jan-06 12:02
Rob Caldecott30-Jan-06 12:02 
QuestionCreating my own control Pin
Mutty30-Jan-06 8:12
Mutty30-Jan-06 8:12 
AnswerRe: Creating my own control Pin
Maximilien30-Jan-06 8:45
Maximilien30-Jan-06 8:45 
GeneralRe: Creating my own control Pin
Mutty30-Jan-06 8:51
Mutty30-Jan-06 8:51 
AnswerRe: Creating my own control Pin
ddmcr30-Jan-06 9:20
ddmcr30-Jan-06 9:20 
QuestionIs there a bug in VC++ 6.0 Compiler? Pin
RanjanShrestha30-Jan-06 7:38
RanjanShrestha30-Jan-06 7:38 
AnswerRe: Is there a bug in VC++ 6.0 Compiler? Pin
Chris Losinger30-Jan-06 7:44
professionalChris Losinger30-Jan-06 7:44 
GeneralRe: Is there a bug in VC++ 6.0 Compiler? Pin
RanjanShrestha30-Jan-06 8:02
RanjanShrestha30-Jan-06 8:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.