Not me
June 8th, 2009, 05:09 AM
How would this be done using API?
char *lpBuffer;
lpBuffer = new char[size];
char *lpBuffer;
lpBuffer = new char[size];
|
Click to See Complete Forum and Search --> : [RESOLVED] Memory allocation API Not me June 8th, 2009, 05:09 AM How would this be done using API? char *lpBuffer; lpBuffer = new char[size]; wigga June 8th, 2009, 07:07 AM http://msdn.microsoft.com/en-us/library/aa366597(VS.85).aspx kudos please Not me June 8th, 2009, 08:44 AM Thanks Wigga What do you think of using this function? VirtualAlloc wigga June 8th, 2009, 09:13 AM using the heap is faster.. tell me what you want todo Not me June 8th, 2009, 12:12 PM open file and assign the ReadFile() function to read into this newly allocated buffer lpBuffer instead of using newoperator to allocate memory What thos this mean if you can explain - It is an ATTRIBUTE for HeapCreate. Execute code from memory? I can load an executable into memory and execute it from memory? HEAP_CREATE_ENABLE_EXECUTE 0x00040000 All memory blocks that are allocated from this heap allow code execution, if the hardware enforces data execution prevention. Use this flag heap in applications that run code from the heap. If HEAP_CREATE_ENABLE_EXECUTE is not specified and an application attempts to run code from a protected page, the application receives an exception with the status code STATUS_ACCESS_VIOLATION. Igor Vartanov June 9th, 2009, 05:27 AM open file and assign the ReadFile() function to read into this newly allocated buffer lpBuffer instead of using newoperator to allocate memoryWhat is this all mostly about? Having a dynamic buffer size? What's wrong with 'new' operator? Besides, are you sure you need that memory allocated in heap but not stack? Not me June 9th, 2009, 05:41 AM Nothing is wrong with new I'm doing it with API functions and want to know how is the best way to do it. I need to allocate the same memory new operator allocates. Yeah, i need dynamic buffer size. But ok I managed to do it, now i have a subquestion. How to assign data stored in that memory to another variable? Copy that memory data to its location? So is CopyMemory a best way to do it? wigga June 9th, 2009, 10:27 AM it all depends on the file you are readding. 1. is it in text format 2. is it in binary format what is the data inside the file?? Not me June 9th, 2009, 12:49 PM This is another problem, file is binary but i manged to read it. File and allocation are no more problems. Well there is no problem but im interested what function is the best to use: lpPathBuffer = lstrcat(lpBuffer, "\\*.*"); Both variables are pointers and after this function both variables point to same address. The address holds path for C: and after function it would be C:\*.* I want one variable to stay C: because i have to use it for subfolders in a recursive search. If a folder is found The path would be C:\folder So i guess i will have to make a copy of variable each time i call the function and then delete it. Overall, Im stuck here, in this recursive file search. Not me June 9th, 2009, 12:53 PM Ok, the problem is i want to use = but i cant use it with pointers because that will make them point at same memory and i wont get what i want, two variables with same values but different memory locations. wigga June 10th, 2009, 08:31 AM To help you more in this i need to know the format of the file. And i need to see more of your code. Just saying that problem is you want to use the operator = and talking about some variables pointing at the same memory is just confusing me. Not me June 10th, 2009, 10:12 AM How would you declare variable lpBuffer and alocate the memory for it? DWORD dwDriveList = GetLogicalDriveStrings(255, lpBuffer); Here is the function info: DWORD WINAPI GetLogicalDriveStrings( __in DWORD nBufferLength, __out LPTSTR lpBuffer ); Parameters: nBufferLength [in] The maximum size of the buffer pointed to by lpBuffer, in TCHARs. This size does not include the terminating null character. If this parameter is zero, lpBuffer is not used. lpBuffer [out] A pointer to a buffer that receives a series of null-terminated strings, one for each valid drive in the system, plus with an additional null character. Each string is a device name. Return Value If the function succeeds, the return value is the length, in characters, of the strings copied to the buffer wigga June 10th, 2009, 10:59 AM TCHAR lpBuffer[255]; Not me June 10th, 2009, 05:09 PM I guess i was doing it the harder way but when i used char* i got error for function parameters... Thank you. codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |