Practical Usage of Virtual Memory - memory

I have used the code
MEMORYSTATUSEX memInfo;
memInfo.dwLength = sizeof(MEMORYSTATUSEX);
GlobalMemoryStatusEx(&memInfo);
DWORDLONG totalVirtualMem = memInfo.ullTotalPageFile;
DWORDLONG virtualMemUsed = memInfo.ullTotalPageFile - memInfo.ullAvailPageFile;
DWORDLONG totalPhysMem = memInfo.ullTotalPhys;
provided at here
Output is like: 2.3GB.
totalVirtualMem = 8.5 Gb
virtualMemUsed = 2.3 Gb
totalPhysMem = 4 Gb
Does this means that my program requires 2.3Gb of memory? Could you also comment on total virtual memory and RAM? Also I was not able to run this code:
PROCESS_MEMORY_COUNTERS_EX pmc;
GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc));
SIZE_T virtualMemUsedByMe = pmc.PrivateUsage;
as it gives error as,
error C2664: 'GetProcessMemoryInfo' : cannot convert parameter 2 from 'PROCESS_MEMORY_COUNTERS_EX *' to 'PPROCESS_MEMORY_COUNTERS'

I stumbled upon exactly the same Problem and found out that a simple type cast solved it for me.
PROCESS_MEMORY_COUNTERS_EX pmc;
GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc));
SIZE_T virtualMemUsedByMe = pmc.PrivateUsage;
The solution is also described here (msdn: Question about GetProcessMemoryInfo).

Related

OpenCV detect and compute image features

Recently upgraded OpenCV from 3.4.5. to OpenCV 4.2.0.
Before I followed this stitching example: https://github.com/opencv/opencv/blob/5131619a1a4d1d3a860b5da431742cc6be945332/samples/cpp/stitching_detailed.cpp (particularly line 480). After upgrading, I altered the code to align more with this newer example: https://github.com/opencv/opencv/blob/master/samples/cpp/stitching_detailed.cpp (Note line 481).
Problem is with this new computeImageFeatures function, I am getting less detected features. Older code with same images gave me 1400+ features but computeImageFeatures gave me exactly 500 features per image. Any ideas how to "fix" this? I believe it also causes the "Bundle Adjuster" to fail later.
According to documentation of cv::ORB::create, default value of nfeatures argument is 500:
The first argument is nfeatures, you may set the first argument to grater number like 2000.
Here are the constructor arguments:
static Ptr<ORB> cv::ORB::create (int nfeatures = 500,
float scaleFactor = 1.2f,
int nlevels = 8,
int edgeThreshold = 31,
int firstLevel = 0,
int WTA_K = 2,
int scoreType = ORB::HARRIS_SCORE,
int patchSize = 31,
int fastThreshold = 20
)
Try modifying:
if (features_type == "orb")
{
finder = ORB::create();
}
to
if (features_type == "orb")
{
finder = ORB::create(2000);
}
In case you are not using ORB, but other type of features, read the documentation of the constructor.
I assume all types has a limiter argument.

lua dissector for a float variable returns zero

I'm trying to read a float variable from the buffer but i'm getting a zero value.
This is the code i used:
-- Create fields
str_format=string.format
p_Genie.fields = {}
local fields = p_Genie.fields
fields.number_field = ProtoField.float("p_Genie.number", "Number",base.DEC)
function addFloat32(tree, buf, start, name, floatSize)
local rang = buf(start, floatSize)
local ti = tree:add_le(fields.number_field, rang)
ti:set_text(str_format("%s %f", name, rang:le_float()))
return floatSize
end
What am i doing wrong?
Thanks.
I don't think your use of ProtoField.float is correct. According to Section 11.6.7.16 of the Wireshark Developer's Guide, the 3rd argument is an optional valuestring, not a base. Maybe start by fixing that and see if it resolves your problem.

ImageMagick compare images with API?

I have the following code:
MagickWand *wand = NewMagickWand();
char* cmdargs[] = {
"compare",
"receipt-expected.png",
"-metric",
"psnr",
"difference.png",
"difference2.png",
NULL
};
int argcount = 6;
// Allocate memory for MagickCommand
ImageInfo * info = AcquireImageInfo();
ExceptionInfo* e = AcquireExceptionInfo();
// Execute command
char *metadata = NULL;
MagickBooleanType status = MagickCommandGenesis(info, CompareImageCommand, argcount, cmdargs, &metadata, e);
status is 0, which I assume it working because it has no error and the command works correctly in the CLI.
How do I get the metric it has produced? meta is NULL.
$ compare receipt-expected.png -metric psnr difference.png difference2.png
15.4169
Ideally you would access the API directly, rather than attempting to call a new ImageMagick process as a subprocess.
MagickWand * alpha, * beta, * result;
// ... Allocated & Init `alpha' & `beta'
double metric;
result = MagickCompareImages(alpha,
beta,
PeakSignalToNoiseRatioMetric,
&metric);
printf("psnr = %f\n", metric);
How do I get the metric it has produced?
You can not, as metadata is intended to hold additional IO information in a heap. In this instance, any information written to char ** metadata will be destroyed immediately after the internal command writes to standard output. See here for reference.

Xtext - Java 64K limitation in generated Parser

I'm working on a quite large grammar and it looks like I have a problem with the Java 64K limitation.
The Mwe2 configuration needs about 1024MB Heap for the generation, but after about 6 minutes, an error message is reported: "The code of constructor x() is exceeding the 65535 bytes limit".
As the Java 64K limitation is a known issue, so I quickly found some solutions and configured the workflow with the following:
fragment = parser.antlr.XtextAntlrGeneratorFragment auto-inject {
antlrParam = "-Xconversiontimeout" antlrParam = "60000"
options = {
classSplitting=true
fieldsPerClass = "200"
methodsPerClass= "500"
}
}
fragment = parser.antlr.XtextAntlrUiGeneratorFragment auto-inject {
antlrParam = "-Xconversiontimeout" antlrParam = "60000"
options = {
classSplitting=true
fieldsPerClass = "500"
methodsPerClass= "500"
}
partialParsing=true
}
But nothing has changed. The removing of partialParsing also doesn't have any effect.
Has anyone already face the same and could give me a tip for this issue?
Is there something I could do about this error?
Thanks

Heap corruption detected - iPhone 5S only

I am developing an app that listens for frequency/pitches, it works fine on iPhone4s, simulator and others but not iPhone 5S. This is the message I am getting:
malloc: *** error for object 0x178203a00: Heap corruption detected, free list canary is damaged
Any suggestion where should I start to dig into?
Thanks!
The iPhone 5s has an arm64/64-bit CPU. Check all the analyze compiler warnings for trying to store 64-bit pointers (and other values) into 32-bit C data types.
Also make sure all your audio code parameter passing, object messaging, and manual memory management code is thread safe, and meets all real-time requirements.
In case it helps anyone, I had exactly the same problem as described above.
The cause in my particular case was pthread_create(pthread_t* thread, ...) on ARM64 was putting the value into *thread at some time AFTER the thread was started. On OSX, ARM32 and on the simulator, it was consistently filling in this value before the start_routine was called.
If I performed a pthread_detach operation in the running thread before that value was written (even by using pthread_self() to get the current thread_t), I would end up with the heap corruption message.
I added a small loop in my thread dispatcher that waited until that value was filled in -- after which the heap errors went away. Don't forget 'volatile'!
Restructuring the code might be a better way to fix this -- it depends on your situation. (I noticed this in a unit test that I'd written, I didn't trip up on this issue on any 'real' code)
Same problem. but my case is I malloc 10Byte memory, but I try to use 20Byte. then it Heap corruption.
## -64,7 +64,7 ## char* bytesToHex(char* buf, int size) {
* be converted to two hex characters, also add an extra space for the terminating
* null byte.
* [size] is the size of the buf array */
- int len = (size * 2) + 1;
+ int len = (size * 3) + 1;
char* output = (char*)malloc(len * sizeof(char));
memset(output, 0, len);
/* pointer to the first item (0 index) of the output array */
char *ptr = &output[0];
int i;
for (i = 0; i < size; i++) {
/* "sprintf" converts each byte in the "buf" array into a 2 hex string
* characters appended with a null byte, for example 10 => "0A\0".
*
* This string would then be added to the output array starting from the
* position pointed at by "ptr". For example if "ptr" is pointing at the 0
* index then "0A\0" would be written as output[0] = '0', output[1] = 'A' and
* output[2] = '\0'.
*
* "sprintf" returns the number of chars in its output excluding the null
* byte, in our case this would be 2. So we move the "ptr" location two
* steps ahead so that the next hex string would be written at the new
* location, overriding the null byte from the previous hex string.
*
* We don't need to add a terminating null byte because it's been already
* added for us from the last hex string. */
ptr += sprintf(ptr, "%02X ", buf[i] & 0xFF);
}
return output;

Resources