|
Hi all,
I wish to malloc a large char array (to handle appr. 1 MB file sizes), how can I do that without cracking my computer wide open?
/Tommy
|
|
|
|
|
If you absolutely need to have a contiguous block of memory of 1MB, go ahead and request to malloc a block that big. Chances are there'll be no serious problems, as 1MB is handlable by PCs these days, and moreover the virtual paging mechanism will help liven things up.
Apart from this, maybe you can get by with some block of memory that grows on demand, so that only gets to these huge sizes when actually required. If so, have a look at std::vector , which automates this behavior for you.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquin is right!
Better allocate the memory as you need it:
with malloc and realloc I normally use! So you don't have to allocate on 1MB up front!
Al
|
|
|
|
|
Malloc will work just fine with one warning.
The only problem I have ever run into with allocating large blocks of memory is that if you allocate/free that block a lot, you run the risk of fragmenting your virtual address space. This can happen if you free that 1MB block and then part of it is used by a smaller allocation. Then when you go and try to allocate 1MB again, the system has to allocate a new 1MB block.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Have you considered memory mapping the file? Not only is this faster than reading the file into a buffer, but it will be read into memory on demand (as you access the different parts of the file).
Chris
|
|
|
|
|
Nope, haven't... How do I do that?
/T
|
|
|
|
|
CodeProject may have some examples, I am not sure. Look through the help for the function MapViewOfFile(). Richter also talks about memory mapping in depth in his book advanced windows programming.
Chris
|
|
|
|
|
In the VC6 IDE it was simply Alt-Enter, Down arrow to HTML. I haven't been able to figure out yet how to ask the VC7 MDE to color .shtml files. (It does .html automatically)
- Jason
(SonorkID 100.611)
"The sort of guy who'd give the kid an extra scoop of ice cream free if he was an ice-cream man"
- Nish, on Chris Maunder
|
|
|
|
|
|
The Dragon Book is a good place to start.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Look for information on reverse polish notation.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
In BNF statement, there is a symbol can express "empty" meaning.
But I don't know how to express "empty" meaning in YACC decription file?
I'm amumu, and you?
|
|
|
|
|
I'd say it is more or less like this:
emptyrule :
; but I could be totally wrong
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
I am pretty new to VC++, I mainly use it to create small dialog-based apps using the Windows API. However, at the moment I am trying to create a progress bar using the CProgressCtrl with a window created using CreateWindowEX() (I don't want to use the normal CreateWindow...PROGRESS_CLASS method for the bar as I want to use an extended class that can create a progress bar with gradient colours). This sounds stupid, but I am completely stumped on how to create a progress bar this way. My problem seems to lie with the difference between CWnd and HWND. The parent window that I want to use for the control is not a dialog, but has been created using CreateWindowEx(), and I can't find any examples on the net of how to do this properly (all the examples I can find relate to dialog-based apps). This is the code I am trying to use:
CProgressCtrl MyProgressBar;
CWnd *parentwindow = CWnd::FromHandlePermanent(hwnd);
//hwnd = windows window created using CreateWindowEx()...
MyProgressBar.Create(WS_VISIBLE|WS_CHILD|PBS_SMOOTH,CRect(10,10,200,30),parentwindow,1);
This is all in WinMain(). Everything compiles okay, but when I run the executable I get an assertion error (line 19 of afxwin1.inl, or some such) and of course, there is no sign of the progress bar.
If anyone could tell me what I am doing wrong (and I know it's something really stupid owing to the fact that I'm a novice programmer), I would be very grateful.
Many thanks,
Keith
|
|
|
|
|
This is all in WinMain()
I guess this is where the problem lies. If you're dong raw Win32 apps (which provide of a WinMain ) you've got no MFC support. CProgressCtrl is an MFC class, so it's on wonder nothing works. Create a new project and select the "MFC app" type (or something like that.) The way of writing programs changes from what you're used to, but it doesn't take long to get a passing idea of how it works.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi, thanks for your reply. I've got my program set up so that it's using "MFC in a shared DLL", and there I no errors when I compile. Is it the case that you can't use MFC and WinAPI together? Sorry for the dumb question, but I've never used MFC before. If that's the case I guess I'll have to get learning MFC, unless there is some way of using a gradient coloured control bar in WinAPI (it's the only feature I need to add to my program...).
Again, thanks for your help.
Cheers,
Keith
|
|
|
|
|
Keith, imho you're much better off using MFC (as Joaquín suggested). You could then just use this class.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Thanks for your reply. That's actually one of the classes I was looking at using. Looks like I'll have to go away and learn MFC...
Thanks again,
Keith
|
|
|
|
|
How can I use drag'n drop to get the HWND of the target application window? Is it possible ?
thx
<view next="">
|
|
|
|
|
WindowFromPoint(CursorPos);
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
|
Hello,
I need to use a dll file (that I downloaded from the net) in my MFC VC++ application, but I am new to dll's and VC++ and don't know where to start. I was hoping that someone knew of a document that I could read that would show me how to do this.
Thanks,
Aoife
|
|
|
|
|
What kind of a DLL you have downloaded,
and how do you intend to use that..
|
|
|
|
|
Typically, the DLL is going to come with a header file and an import library.
1) Simply include the header file where you need to - either in the file that will be references any of the DLL's exported types or functions) or in the stdafx.h file
2) Add the import library to the project.
3) Place the DLL in one of the following folders
(This is the order windows searches for DLLs)
The current folder
The Windows folder
The Windows system folder
The folder where the main application is being run from
The folders listed in the PATH environment variable
A mapped network folders
Let me know if you need any more help.
Cheers,
Tom Archer
Author, Inside C#
Please note that the opinions expressed in this correspondence do not necessarily reflect the views of the author.
|
|
|
|
|
If the DLL doesn't come with an import lib, you can get at an exported function by using GetProcAddress() . However, you'll still need a .h file that describes the function's prototype.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|