Search Results

Search found 4 results on 1 pages for 'minjang'.

Page 1/1 | 1 

  • Modifying C# dictionary value

    - by minjang
    I'm a C++ expert, but not at all for C#. I created a Dictionary<string, STATS>, where STATS is a simple struct. Once I built the dictionary with initial string and STATS pairs, I want to modify the dictionary's STATS value. In C++, it's very clear: Dictionary<string, STATS*> benchmarks; Initialize it... STATS* stats = benchmarks[item.Key]; // Touch stats directly However, I tried like this in C#: Dictionary<string, STATS> benchmarks = new Dictionary<string, STATS>(); // Initialize benchmarks with a bunch of STATS foreach (var item in _data) benchmarks.Add(item.app_name, item); foreach (KeyValuePair<string, STATS> item in benchmarks) { // I want to modify STATS value inside of benchmarks dictionary. STATS stat_item = benchmarks[item.Key]; ParseOutputFile("foo", ref stat_item); // But, not modified in benchmarks... stat_item is just a copy. } This is a really novice problem, but wasn't easy to find an answer. EDIT: I also tried like the following: STATS stat_item = benchmarks[item.Key]; ParseOutputFile(file_name, ref stat_item); benchmarks[item.Key] = stat_item; However, I got the exception since such action invalidates Dictionary: Unhandled Exception: System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext() at helper.Program.Main(String[] args) in D:\dev\\helper\Program.cs:line 75

    Read the article

  • Calling some functions before main in C

    - by minjang
    I'd like to do some stuffs before main function. I have multiple source files. In each file, there is some work that needs to be done before main. It was no problem in C++, but problematic with C. In C++, this can be done by two ways: Exploiting a constructor of a global class/struct. Calling a function to a global variable For example, static const int __register_dummy_ = __AddRegisterMetaInfo(...); However, in C, either ways is impossible. Obviously, there is no constructor. So, the first option is inherently impossible. I thought that the second option would be possible, but not compiled in C (I tested only with Visual C++. It gives C2099.). C only allows a constant to a non-automatic variable. Is there any way to call some functions before main?

    Read the article

  • C/C++ memory usage API in Linux/Windows

    - by minjang
    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. However, I need to do it on Linux. I'm trying to find Linux system APIs that are equivalent GetProcessMemoryInfo and GlobalMemoryStatusEx. I found 'getrusage'. However, max 'ru_maxrss' (resident set size) in struct rusage is just zero, which is not implemented. Also, I have no idea to get system-wide free memory. Current workaround for it, I'm using "system("ps -p %my_pid -o vsz,rsz");". Manually logging to the file. But, it's dirty and not convenient to process the data. I'd like to know some fancy Linux APIs for this purpose.

    Read the article

  • Sharing a global/static variable between a process and DLL

    - by minjang
    I'd like to share a static/global variable only between a process and a dll that is invoked by the process. The exe and dll are in the same memory address space. I don't want the variable to be shared among other processes. Elaboration of the problem: Say that there is a static/global variable x in a.cpp. Both the exe foo.exe and the dll bar.dll have a.cpp, so the variable x is in both images. Now, foo.exe dynamically loads (or statically) bar.dll. Then, the problem is whether the variable x is shared by the exe and dll, or not. In Windows, these two guys never share the x: the exe and dll will have a separate copy of x. However, in Linux, the exe and dll do share the variable x. Unfortunately, I want the behavior of Linux. I first considered using pragma data_seg on Windows. However, even if I correctly setup the shared data segment, foo.exe and bar.dll never shares the x. Recall that bar.dll is loaded into the address space of foo.exe. However, if I run another instance of foo.exe, then x is shared. But, I don't want x to be shared by different processes. So, using data_seg was failed. I may it use a memory-mapped file by making an unique name between exe and dll, which I'm trying now. Two questions: Why the behavior of Linux and Windows is different? Can anyone explain more about this? What would be most easiest way to solve this problem on Windows?

    Read the article

1