I'd like to obtain memory usage information for both per process and system wide. In Windows, it's pretty easy. GetProcessMemoryInfo and GlobalMemoryStatusEx do these jobs greatly and very easily. For example, GetProcessMemoryInfo gives "PeakWorkingSetSize" of the given process. GlobalMemoryStatusEx returns system wide available memory.
...
I have #define values in headers that I certainly want Doxygen to document but I have others in C files that I treat as static constants and I don't want Doxygen to document them. Something as simple and stupid as
#define NUMBER_OF(a) (sizeof((a))/sizeof((a)[0]))
#define MSTR(e) #e
How can I keep Doxygen from putting those #defines i...
Instead of declaring a function pointer typedef for a function, is it possible to get it from the function declaration?
Typically,
int foo(int x);
typedef int (*fooFunc)(int);
fooFunc aFunc;
What I want:
int foo(int x);
foo* aFunc;
I want to use it for dlsym:
foo* aFunc;
aFunc = dlsym(lib, "foo");
aFunc(x);
If I update foo and ...
I'm using a small Python script to generate some binary data that will be used in a C header.
This data should be declared as a char[], and it will be nice if it could be encoded as a string (with the pertinent escape sequences when they are not in the range of ASCII printable chars) to keep the header more compact than with a decimal o...
In:
struct foo {
unsigned bar : 2;
};
What does the ': 2' do?
...
I'm a beginner with C programming, but I was wondering what the difference was between the using typedef when defining a structure versus not using typedef. It seems to my like there's really no difference, they accomplish the same.
struct myStruct{
int one;
int two;
};
vs.
typedef struct{
int one;
int two;
}myStruct;...
I read this question and its answer in a book. But I didn't understand the book's justification.
Have a look:
Question:
Will the following code compile?
int main()
{
char str[5] = "fast enough";
return 0;
}
And the answer was:
Yes.The compiler never detects the
error if bounds of an array are
exceeded.
I cou...
I'm reading some code of a model malloc (allocateMemory). I have posted a portion of the code, but I couldn't understand the purpose of size = (size_in_bytes + sizeof(int) - 1) / sizeof(int); (The last line in the posted code)
void initializeHeap(void) {
/* each chunk requires two signatures, one at the top and one
* at the bot...
My code is something like this:
DIR* pDir = opendir("/path/to/my/dir");
struct dirent pFile = NULL;
while ((pFile = readdir())) {
// Check if it is a .zip file
if (subrstr(pFile->d_name,".zip") {
// It is a .zip file, delete it, and the matching log file
char zipname[200];
snprintf(zipname, sizeof(zipname), "/pat...
So, I've recently noticed that our development server has a steady ~300MB out of 4GB ram left after the finished development of a certain project. Assuming this was due to memory leaks during the development phase, will that memory eventually free itself up or will it require a server restart. Are there any tools that can be used to prev...
How to add libraries in Eclipse project in C in Linux?
...
In VMs OS-provided real-time scheduling tends not to be reliable. For my application I'd like to be able to detect whether I am running on a VM or not (Linux-only).
So I am looking for a nice way to detect (in C) whether I am in a virtualized environment. Depending on the VM used there seem to be various DMI and CPUID strings in use. I...
Can I use the code generated by flex/bison|lex/yacc in a multithreaded environment ? I'm afraid there are a lot of global variables. How can it be fixed ?
...
As I know, an array needs to have a specific size before compiling time in c.
I wonder why this code still works?
int s;
printf("enter the array size: ");
scanf("%d",&s);
int a[s]; // Isn't s value determined at run time?
...
I have this piece of code in c:
int q=10;
int s=5;
int a[3];
printf("Address of a: %d\n",(int)a);
printf("Address of a[1]: %d\n",(int)&a[1]);
printf("Address of a[2]: %d\n",(int)&a[2]);
printf("Address of q: %d\n",(int)&q);
printf("Address of s: %d\n",(int)&s);
The output is:
Address of a: 2293584
Address of a[1]: 2...
Here is my code:
#include <stdio.h>
#include <string.h>
#include <errno.h>
int cmp(const void *a, const void *b) {
const char **ia = (const char **)a;
const char **ib = (const char **)b;
return strcmp(*ia, *ib);
}
void print_array(char **array, size_t len) {
size_t i;
for(i=0; i<len; i++) {
printf("%s, ", a...
int main(void) {
int x = 0;
char* p = (char*) &x;
int k = 0;
while (x != -1) {
*p = -1;
p = p + 1;
k = k + 1;
}
printf("%d", k);
}
We have already set p to the address of x with char* p = logically, *p=-1 should have replaced the value of x on the first iteration (k=1). In reality (or when I ran the code in VS...
I am looking at some C code, and have noticed it is full of these curly braces surrounding blocks of code without any sort of control structure. Take a look-see:
//do some stuff . . .
fprintf(stderr, "%.2f sec\n", (float)(clock() - t) / CLOCKS_PER_SEC);
{
//a block! why not?
char *tmp_argv[3];
tmp_argv[0] = argv[0]; tmp_arg...
Hey, so I'm making an iPhone app and in there is a common function that needs to be called. So I put it in it's own file and set it up, passing the parameters to that and all that. However, I'm not sure how best to return the values from the function. I read up trying to return the values in an array, but I'm not sure how to do it.
i...
Hi,
I just heard from somewhere that for numerical computation, "Matlab does offer some user-friendly APIs. If you call these APIs in your C/C++ code, you can speed up computation dramatically."
But I did not find such information in Matlab documents like http://www.mathworks.com/support/tech-notes/1600/1622.html and http://www.mathwor...