« first day (1596 days earlier)      last day (1257 days later) » 

12:30 AM
@mark_c What exactly do you mean by "remains in memory?"
If you are inspecting the memory location previously occupied by the arrays, and noticing the bytes haven't been reset, that is normal. It would be an error to assume deleting memory clears it.
If a memory management analysis tool like valgrint is complaining, then that would be something to investigate.
If you are simply noticing that the memory usage of your application does not go down after deleting your arrays, that can also be normal. The process is not required to immediately return the freed memory to the OS. I can keep it for later if it chooses.
 
 
7 hours later…
user12698128
7:31 AM
@FrançoisAndrieux I pass those buffers to the waveoutwrite and obviously sounds are played.
After calling delete, I try to play the buffers again and they play again; I was expecting an exception. Do you mean that in reality the memory is freed from the OS and I'm just playing "dirt"?
 
nwp
11:20 AM
@mark_c Typically implementations of new/malloc never return memory back to the OS. They simply hold onto it and give it to you again next time you call them. So if you keep allocating memory, sending it to be played and then deleting it you will actually have the same buffer be used repeatedly and the OS will not be involved besides the first allocation to be fast.
But yes, you are playing dirty with memory that doesn't belong to you and it's undefined behavior. One possible outcome is that the sounds play as normal. Another possible outcome is that you used std::cout << "Now playing"; and std::cout happens to allocate memory and write the text into it and now parts of the sound have wrong values. Or the program terminates because you used address sanitizer.
Also what PeterT said, you do need to use delete [] on memory acquired by new [], otherwise that is UB already.
 
user12698128
ok, thanks everyone for your time, you were very accurate
 
12:25 PM
@nwp not universally true HeapAlloc will definitely release memory back to the OS if it has enough (multiple completely free pages) and I'm pretty sure glibc's malloc does the same. Large allocations are always released back to the OS IIRC.
 
1:11 PM
@mark_c so weird fact of how windows manages memory, in order to keep compat with programs that are dumb windows will keep deallocatd pages mapped but not resident in applications. If an application touches the page then it puts the entire process in a compatibility mode where it never actually frees memory. It will eventualy reclaim the page and zero it if you don't touch it for long enough. But it's actually the OS trying to 'help you' even though you're actually causing a use after free bug
 
 
6 hours later…
user12698128
6:54 PM
hello, in order to store a sample generated by my function, to calculate the buffer size I do this: size_buffer = 44100 * time * 2
where 2 is the number of channels, time is the time in seconds.
Is this the way?
Thanks
 
7:49 PM
sure, if 44.1kHz is the sampling rate, but I assume you set that before
 

« first day (1596 days earlier)      last day (1257 days later) »