|
As can you see in the code I used delete[], I used also delete only and in release mode but the memory was not freed.
By using static allocation my program used 26MB only.
I tried this simple code and worked fine:
#include <stdio.h>
void main()
{
long i,size=((long)(1024L*1024L*50L/6L))*6;
for (i=0;i<100;i++)
{
__int16 (*memory)[6]=new __int16[1024L*1024L*50L/6L][6];
memory[1024L*1024L][5]=132;
delete memory;
printf("\nAllocated and deallocated %li MB",i*(size/1024L)*sizeof(__int16)/1024);
}
printf("\n=== FIN ===");
getchar();getchar();
}
Perhaps the visual studio could not deallocate the memory to be reused because any operation reason
|
|
|
|
|
I saw that you used the array form there. My suggestions was to check it elsewhere in your program.
When checking it again I saw that you use this:
delete[] filtro2,filtro3;
Asking myself if this is allowed, I searched and found that it is allowed but is a so called placement delete which effectively does nothing.
Use this instead and try your original code:
delete[] filtro3;
delete[] filtro2;
|
|
|
|
|
YES, you are right
Thank you very much, you solved me a lot of problems
|
|
|
|
|
I think we have both learned something new today (I did not know the placement delete before)
|
|
|
|
|
More than the two of you learned something new.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
About using the task manager>process window, I found that there is an error of memory used varies about 4k from one run to the following, so it can be used to see memory variations in debug sessions taken in account that.
I used it to run the following very simple code:
#include <stdio.h>
void program_good()
{
char *memory=new char[10000L*1024L];
memory[1024]=' ';
delete[] memory;
}
void program_bad()
{
char *memory=new char[10000L*1024L];
memory[1024]=' ';
}
void main()
{
double x[10];
char ptr0[1024];
program_good();
char ptr1[1024];
printf("\nMemory diference=%li",(long) (&ptr1-&ptr0-1024));
program_bad();
char ptr2[1024];
printf("\nMemory diference=%li",(long) (&ptr2-&ptr1-1024));
printf("\n=== FIN ===");
getchar();getchar();
In the task manager I found that my "Prueba.exe" memory usage was:
step #1 and #2: 484k
step #3: 10508k
step #4: 484k
step #5: 492k (I do not know why printf used 8kb)
step #6: 10516k
As result the calling of the program_bad() leaks 10Mb plus 32kb
So the task manager is not an exact tool but can help
|
|
|
|
|
Good to know, but I was refering more to Jochen's 'discovery' of placement delete.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Good catch.
|
|
|
|
|
Member 11988283 wrote:
I used the windows task manager and I found that the delete command does not frees memory. The numbers you see in Task Manager are almost, but not quite completely, useless for telling how much of your program's memory is in use. If you see it shrink, fine, but if you don't, it is not necessarily bad.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
task manager isn't going to help you much.
at a high level, it works something like this:
when you allocate memory, it comes from your process's heap - if that heap is too small, it allocates more from the OS (up to the OS's per-process memory limit). when you free memory, it typically goes back to the process's heap, not back to the OS. this happens because it's common for a program to allocate/free the same amount of memory over and over, and it's quicker to just grab memory from the process's heap than to get the OS involved. so, under normal situations, your heap rarely shrinks. it typically grows and grows until it gets big enough to keep your program satisfied. it's only when your app shuts down that the heap memory is finally and completely released back to the OS.
if the OS itself is running low on memory, it will start grabbing unused heap memory from your process. so sometimes you'll see Task Manager show a drop after a large free - some other process needs a large contiguous block and the OS hands it over. but don't count on that.
|
|
|
|
|
I tried with VS2008 and it fails to allocate more than 2GB becaus delete command does not free memory.
Using VS2015 (x86) fails also
Using VS2015 x64 fails but more than 4GB are allocated
|
|
|
|
|
Hi all,
I have a project written with VS6.0 C++ (MFC). In that project we use WININET to accomplish FTP download files from server; now we are asked to use Secured FTP (SFTP).
As I read from sites and forums, WININET doesn't support SFTP. My question: is there a third party that I could include in my project to be able to use SFTP?
Thank you in advance.
"The Only Limit Is Only Your Imagination."
|
|
|
|
|
Friends i have made a registry entry using MFC application written in visual studio 2012 64bit and i compiled it when i open the exe in assembler it shows some unreadable text but the exact registry path of mine is seen cleary.How to hide this or secure the entry...
Please share your ideas...
|
|
|
|
|
If all that interests you is obfuscation, any simple routine (such as XORing the string with another string) will hide the string. However, any serious attempt at reverse-engineering your code will use an API logger to see what your code is actually doing.
As it is always possible to intercept a Windows API, any serious attempt to hide a registry key is doomed to failure. You might want to look into encrypting the contents of the key (i.e. using a binary blob rather than a string). Many encryption algorithms exist, depending on the level of security required.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
Daniel Pfeffer wrote: (i.e. using a binary blob rather than a string). I agree.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
je veux le programm en c ou en java pour celui qui a une idee je rend le projet apres une semaine
il sagit d'un program pour resoudre une equation differentielle de Riccati et merci
|
|
|
|
|
You will get a better answer by asking in English.
|
|
|
|
|
There are many numeric approaches to solving sets of differential equations. As long as the numerical equations can be represented as a set of functions of the form:
dy(x)/dx = f(x)
you should find an appropriate solver. One family of numerical solvers is the Runge-Kutta family, and there are many others. Any numerical analysis book should have details.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
Hi,
I got this strange compiler error here is the source line
for (i=MAX_DECIMAL_DIGITS-1, j=MAX_DECIMAL_DIGITS-1-effective_addr2;
i >= 0; i--, j--)
The solution/project project compiles cleanly in a different directory where the other source files are different but the source file is the same
thanks
|
|
|
|
|
That error message is a bit confusing. It mentions a source line at first, but then shows an error in the linker.
|
|
|
|
|
I was able to generate a "debug" version of the code and it seems to run as fast
I guess I have to look at my properties and see if any entry is incorrect
I look at the linker section
Thanks so much
|
|
|
|
|
I had such compiler errors in the past with older VC versions.
Quote: To work around this problem, try simplifying or changing the program near the locations listed above.
I always solved the problem following the above. There was one case where it could be solved by just exchanging two lines of code. In the other cases, I re-ordered some code or moved code to an additional function.
I don't remember if I had the linker error afterwards too. But it is obviously sourced by the compiler error (the compiler exits immediately when that error occurs).
|
|
|
|
|
Problems:
- C, C++ declining due python and other high level languages
- C, C++ programming structure comes from Jurassic era
- Programmers are always redesigning the wheel
- New software are heavy weight, so they takes lots of time to upload from hard disks
- Every time a new project is written it must be copied the functions so perhaps it exist different functions version in the hard disk
- In the hard disk exists dozen of projects with files and functions distributed in a unclear structure
Proposed solution:
To design a new precompiler (perhaps based in geany) that performs the following tasks:
- Look for all functions in a function directory
- Write them in a tree
- The user drags and drop the functions from the tree using the mouse
- The pre compiler writes the C program to be compiled using only the needed functions
- More over the precompiler can access to web sites with functions written by other users
- In the project it will appear a dictionary that advises what functions are used
- If a function is modified it advises of the affected projects in order to write it with different name
- It will be easily readable in a tree the functions dependence with other functions
- Build the makefile
- User can navigate through the project function tree structure to see one function
- The precompiler adds multithreading headers if it is possible when some functions works in parallel
- The precompiler can change the calling variable type with others (example double to float) and modifying internal function type definitions accordingly
As example the user can write an only one file named “matrix.cpp” that contains ALL matrix functions like the followings. The commented lines before explain the function.
matrix_inverse(double *matrix1,double *matrix2,long N)
matrix_inverse3x3(double *matrix1,double *matrix2)
matrix_multiplier(double *matrix1,double *matrix2,double *result,long N)
How the function tree can be seen:
http://s12.postimg.org/q50hwfpnh/Proposal_of_a_modern_C.png
|
|
|
|
|
|
"Wrong place; please read"
May be but I did not found a better place than "General Discussions>C-C++" and I can not move the post to other place and must not remove the post
|
|
|
|