-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Classify: Avoid unneeded new / delete operations
Both class variables BaselineCutoffs and CharNormCutoffs were pointers to fixed size arrays which were allocated in the constructor and deallocated in the destructor. These two extra allocations and two extra deallocations can be avoided. Signed-off-by: Stefan Weil <[email protected]>
- Loading branch information
Showing
2 changed files
with
2 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83588bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change won't compile at Google. The stack frame is too big. We have limits.
83588bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See also:
https://msdn.microsoft.com/en-us/library/7yhee2f0.aspx
83588bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ray, do you know which variable is causing the "stack frame too big" problem? Could you please post the complete compiler error message?
83588bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GNU compiler can also warn when the stack frame exceeds a certain limit. Here is the result for Tesseract:
The largest stack frame is caused here in file
ccstruct/polyaprx.cpp
. I currently don't see anything related to my change.83588bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe they use clang.
http://clang-developers.42468.n3.nabble.com/clang-and-Wframe-larger-than-td4045414.html
83588bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler option
-Wframe-larger-than
which is mentioned there for clang is also supported by gcc. I used it for the report shown above. As far as I remember, MS Visual C++ has a default limit of 1 MB for the frame size.Ray, if the compile problem occurs with code outside of Tesseract, I suggest to use a pointer variable with new / delete instead of allocating it on the stack. This will still save one new / delete operations (3 before patch, 1 after patch with new / delete, 2 before patch, 0 after patch with variable on stack).
83588bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stefan, did you follow my 2 links above?
83588bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did, but obviously I did not read the text on Visual C good enough. VC uses 16 KB, not 1 MB as the default frame size limit for warnings. Fixed now in my post above. The frame sizes of clang and gcc don't differ much: the largest frame size with clang is 12536 bytes.
83588bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
83588bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I know that my modification increased the size of
Classify
a lot. But I only found code which allocates that class on the heap (using new), no code which allocates it on the stack. The compiler (tested with gcc and clang) also did not find such code.83588bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look at pull request #883.