Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


what is ESP error !!! in VC++ Debug Mode !!

Posted on 2002-06-10
Medium Priority
Last Modified: 2007-12-19
Debug Error !
 Modle :
 file  : i386\chkesp.c
 Line  : 42
 The Value of ESP was not properly saved across a function call.
 This is usually a result of calling a function declared with
 one calling convention with a function pointer declared with
 a different calling Convention..                          

I am programming Server Program..

When Clients Number is small, ESP Error not occured..

but When Large, ESP Error!!!!..

I don't know what is problem ???..

Calling convention is correct ...

I don't know ESP Error..????..

Is there any method skip ESP error in Debug Mode ????..

Question by:jhjeon
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
  • +4
LVL 86

Accepted Solution

jkr earned 400 total points
ID: 7068670
Sounds like a stack overflow to me...
LVL 22

Expert Comment

ID: 7068711
ESP is the "Extended (which you can ignore) Stack pointer" register   In other words, it is a register in the CPU that stores a pointer to the top of the CPU stack.

The CPU stack is somewhat like the stacks you (probably) have learned about in programming.  It is a LIFO "container".  That is the last think placed on the stack in the first thing to be removed.     However a CPU stack stores binary data of essentually any tiype and size--unlike a typical stack container.    The CPU stack is used primarily for storing procedure's (non-static) local variables, parameters, return values, and return addresses for calling procedures.

The C++ compiler is responsible for creating machine code that manages the stack.  When a procedure is called,the parameters are pushed onto the stack, then  the calling procedure's address next instruction is placed on the stack, then the procedure is called.   The calling procedure can access the parameters as needed, when it is done it removed the parameters from the stack and removes the stored return address and returns execution to that return address   (The exact details vary, but that is a typical idea.)

LVL 22

Expert Comment

ID: 7068731
A stack problem typically occurs when the calling and the called function do not agree on the number and size of the parameters, or in how the parameters are to be passed ( like stdcall vs cdecl).  In this case, the called function might look for the return address at the wrong location and thus return to the wrong location.   Or it might not remove all the parameters from the stack, or remove too much.   There are lots of possible errors of this type.

You might look to see if you have a case where you are calling a function via a pointer (like a DLL function loaded with GetProcAddress())   Or if you are providing a function that someone else is calling via a pointer.    These are instances where you can run into these problems.  If you declare the function to use the wrong calling convention or wrong parameters or return value, the stack can get messed up.    (Ussually this is not a problem, because if you have this type of mismatch with a regular function call the compiler will detect it and report it as a compiler error.  But if you try this through a pointer, you can use cast you can circumvent the error and allow the code to compile and then work wrong.)

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 22

Expert Comment

ID: 7068744
I should mention "calling conventions" are the rules that govern the procedures for calling and returning from functions.  They specify the order in which parameters are placed on the stack (and/or registers) and who is responsible for removing the parameters)

In C++ on win32 there are two main calling conventions.  There is "standard call" (__stdcall) and "C-declaration" (__cdecl).      You can look these up in the VC help for more info.

when a function is called, the caller must know (or think it knows) what calling convention the called function uses.  This way they can agree on how to pass parameters etc.   If they don't agree and the code is still forced to compile, then you will get a stack errror.
LVL 86

Expert Comment

ID: 7068747
>>I should mention "calling conventions" are the rules that govern the ...

You are right, but

>>When Clients Number is small, ESP Error not occured..
>>but When Large, ESP Error!!!!..

If the callconv was wrong, not a single call could have succeeded...
LVL 22

Expert Comment

ID: 7068760
I missed that.  That is true.

But on win32 the stack is supposed to grow as needed (within reason) so it takes an extreme case of overuse to overflow a stack (Other than infinite recursion).

There has to be a little more to the storey than that, right?

Author Comment

ID: 7068791
I make Client class...

Storage size of client is about 50000 byte

Storage structure is array..(reciving Queue buffer)
and Some Pointer buffers Etc.(Sending Buffer,
Maximum sending buffer is 999 pointers)

server program supprots 1000 clients (in array)

1000 x 50000 = about 50M..

my system memory is 128M...

ESP error is concerned with System Stack ?
LVL 30

Expert Comment

ID: 7068812
Why don't you try using std::vector instead of a C-Style buffer.
LVL 12

Expert Comment

ID: 7069272
nietod: I don't think that's actually true--on UNIX the stack is automatically resized to accommodate a program's needs, but not on Win32. I know this because I've had to convert a UNIX utility to a Win32 command-line application, and I had to modify it to use malloc()'ed memory rather than the huge local arrays it WAS using because of stack size limitations. (Sure, I could have boosted the size of the stack in the linker, but I thought defining a two hundred thousand entry local integer array was sloppy programming anyway!).

Author Comment

ID: 7069328
um..ESP Error...

is it memory Problem....??

not calling convention problem..?
LVL 30

Expert Comment

ID: 7069453
>>is it memory Problem....??

It's a memory handling problem, and an alternate method of handling your memory could fix the problem.

One method that should fix the problem, is using memory mapping vi Map API's.

CreateFileMapping, OpenFileMapping, MapViewOfFile, and UnmapViewOfFile.
LVL 22

Expert Comment

ID: 7069489
>> Why don't you try using std::vector instead of a C-Style buffer.
Because it will use less memory?    Actually it will use at least as much, probably more.    The only advantage woudl be if the array size is declared larger than it needs to be and the vector wouldn't grow as much.    But there is no evidence of this--at least not yet.

>>  I don't think that's actually true--on UNIX the stack is
>> automatically resized to accommodate
>> a program's needs, but not on Win32.
Its definitely a feature of the x86 chips and I am fairly certain the OS is using it.

>> I've had to convert a UNIX utility to a Win32
You can always specify a larger stack size to the linker.    AFAIK this is the initial stack size, and it will grow from there.

>> Sure, I could have boosted the size of the stack
>> in the linker, but I thought defining a two hundred
>> thousand entry local integer array was sloppy
>> programming anyway!).
defining it as a dynamic array isn't really any different.

>> s it memory Problem....??
> not calling convention problem..?
In this case it is a memory problem.  You are probably running out of memory on your stack.   For the short term you could try increasing your stack size.

Go to the project settings dialog  (project menu)
Link page tab.
Output category
and fill in a the stack size option.    Try a larger value, like 60M.

In the long term, you need to really reconsider your memory ussage.  Its very likely that your program can be using memmory much more effectively than it is currently.   (Maybe)      But we can't really help you with that unless we know more aout what it is doing with these huge arrays/data structures.
LVL 12

Expert Comment

ID: 7070173
nietod: I think it's actually the other way round--my reading of the MSDN (and my experience with the program I mentioned, which crashed with a stack fault exception) is that the reserved stack size in the linker is the MAXIMUM possible size for the stack, not the minimum. Certainly the MSDN documentation on the STACKSIZE module definition statement says that the "reserve" number is the amount of virtual address space reserved for the stack in an .EXE.
LVL 22

Expert Comment

ID: 7070438
Opps.  you could be right.   I'll have to look into that.    Not now though.
LVL 11

Expert Comment

ID: 7261797
Dear jhjron

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to split between

     "jkr & nietod"

comment(s) as an answer.


Expert Comment

ID: 7332921
Force accepted

** Mindphaser - Community Support Moderator **

nietod, there will be a separate question with points for your help.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question