C++ :: Moving Objects To Shared Memory

Feb 9, 2013

I am not so experianced with c++ myself, but I need to evaluate if a certain idea might work.

I am working with a system for automation purposes that is running on a realtime OS in parallel to windows. Windows and the RTOS exchange data via shared memory. The application in the RTOS is compiled in C++. Now I would like to be able to influence the some data manipulation tasks in the RTOS application without changing the code of the RTOS application. So a concept like calling a dll.

My idea was to create a class with virtual methods in the RTOS application. The objects that are used should then be created on the Windows side with the same class prototype, but specific implementation of the virtual methods. The objects should then be moved to the shared memory, where they are used by the RTOS application.

Is something like this possible or am I completly on the wrong path?

View 4 Replies


ADVERTISEMENT

C++ :: Shared Memory To Make Objects Of Application Persistent?

Aug 18, 2014

I have a question concerning shared memory (in linux-environment). In our company we currently have an application that is restarted once in a while. There are multiple instances running of this application (on different physical machines), and all access the same centralized database. Because of IO and Network bottleneck the start gets very slow, and takes about 10 Minutes. Besides some new data, most of the data stays the same, so reading from the database again is quite redundant. An idea is to write all relevant object to a shared memory segment, when the application is shut down. A second dummy process attaches to the same shared memory (just so that some process is still attached). If the application is restarted, it is attached again to its shared memory, and reads it to its own adress range again. There might occur a difference regarding the data so it might me necessary to load some new data afterwards, but that is different problem.

The current idea is to serialize all Objects (could be about 1-2 Gigabyte) with Apache Thrift, and write them into shared memory. With Thrift the data is more or less ordered, so creating the objects anew is possibly easier (not sure here).

My Question is:

- Does it even make sense to consider shared memory in this scenario. I've read a lot stuff about in the last few days, and for now I don't see big disadvantages (except if the application crashes, in this case I've to read from database again). On the other hand I don't know how to really implement this functionality (as I'm no experienced Developer)

- Should I aim for Boost::Interproces, considering even memory mappable files, or stay with the traditional shmat (and stuff..)?

- I guess 1-2 Gigabyte shared memory will be necessary. This amount is only needed in the gap between application shutdown and restart. Will the sheer amount of needed shared memory be a problem (all examples I found just used a few Bytes or Kilobytes)

View 9 Replies View Related

C++ :: Shared Memory Between Processes

Apr 13, 2014

Say now I have a dll, loaded and run by a 32bit program. One of the things that I access from the program in the dll are several 1024x1024 int buffers. However I would like to put some data into those buffers from a external process. And I would like a separate thread in that external process for each buffer. Is there any way I can make that memory space accessible to the external process so I can use my own multi threaded memory transfers to pass that data over provided I ensure that the original process doesn't try to do anything with that data? And I would like to do this without resorting to the Read/WriteProcessMemory functions which are not threadsafe. In short, I want to set up direct memory access between the 2 programs without creating any intermediate shared memory buffers ie I want to set permissions for an existing memory space. Is this possible?

View 1 Replies View Related

C++ :: Saving Moving Objects?

Nov 1, 2013

I'm trying to serialize and deserialize objects, some static (that works) one moving (doesn't work). In the code you can see that the following int-variables discribe the moving circle:

object->phaseFarbe=phase1;
object->phaseKoord=phase;
object->rot=a;

[Code].....

View 1 Replies View Related

C++ :: File Handling Vs Shared Memory?

May 27, 2014

In interprocess communication(IPC) when processe have to share data among each other,why cant they all connect to one single file and share data with basic file handling functions such as read and write?

Why do we need

shared memory(shmget shmat(),shmdt()..etc)
and
mapped memory(mmap(),munmap()..etc)

concepts?

View 3 Replies View Related

C/C++ :: Creating Moving Objects For 2D Game

Oct 21, 2014

I'm working on designing a game in C++ that is similar to the "find the ball under the cup" game. I have a Sonic the Hedgehog icon (weird I know, but it was the first thing that came to mind) that will be hidden underneath one of three rectangular blocks.

Here is how I envision this working:

On the main menu I have 3 buttons which represent 3 different difficulty levels
Easy- blocks move 3 times at a slow speed
Medium- blocks move 5 times at a slightly faster speed
Hard- blocks move 10 times at a fast speed

When the user clicks one of these buttons they will be taken to the game screen.

Sonic will be displayed for 3 seconds and the user will then see him be covered with one of the three blocks.

The three blocks will then move in a random pattern along the middle of the screen at the speed and number of times associated with the button that was pressed.

Once the blocks stop moving, the user is to click on the one they think Sonic is underneath.

If they choose correctly, they'll be taken to a "Winning Screen" that displays a congratulatory message and 2 buttons. Play Again- returns the user to the main menu and the game starts over with a new random pattern. Quit- the window closes.

If they choose incorrectly, they'll be taken to a "Losing Screen" that displays a "Try Again" message and 2 buttons that have the same function as the buttons on the winning screen.

I have never worked with any kind of graphics before other than in HTML and Javascript. I have managed to create the main menu, but how to do the actual game portion of the project. I've been trying to take it a step at a time, (for example, I first figured out how to set the background color for the console window, after I got that right I figured out how to add buttons) but the rest of this seems to depend on each other.

Here is what I have so far:

Main menu:

#include "stdafx.h"
#include <iostream>
#include <Windows.h>
using namespace std;
class MainMenu

[Code]....

So I've got the screens pretty much designed now (with the exception of the game screen itself) but how to tie everything together.

In case my description wasn't too clear, here is a game that I found on Google that is pretty much exactly what I'm looking for. [URL]

View 2 Replies View Related

C :: How To Store Array Of Structure At Shared Memory

Jan 16, 2014

I have one requirement to store an array of structure at shared memory. Also the shared memory should have one counter to store number of elements in the array.

I tried to look at some placed but didn't find anything relevant.

So my first question, is it possible that we can store two things on same shared memory. And second if not then how to achieve the same?

View 5 Replies View Related

C :: Initialize 1D Or 2D Array In Shared Memory (POSIX)

Dec 8, 2014

I am trying to initialize a 2D char array of strings into POSIX shared memory to be shared between 3 other processes. There are plenty of tutorials on how to use a pointer to share a single string or an integer between processes, but I could find no examples on how to initialize 1D or 2D arrays using mmap(). I have posted what I have so far below. It is the first program, which creates the shared memory object and initialize the array char files[20][2][100] with the value files[0][0][0] = ''. What is the proper method to initialize and share an array in C?

(program initializes shared memory object and array)

Code:
#include<fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/mman.h>

int main (int argc, char *argv[]){

[Code] ......

View 5 Replies View Related

C :: Shared Memory / Cannot Read Last Element In A Struct

Jun 27, 2014

I have trouble reading the last element in a struct.I do get the correct value for the first two elements. In my example that is:

a = 11 and c = H
however I get:
b = 0
but I am expecting b=2

I got two files to handle this.The first one is writing data to memory -

Code:

#include <sys/shm.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
}

[code]....

why I cannot get correct value for the third element in my struct?In the second file where I'm reading from memory I allocate some space. Is this incorrect in some way? I'm running this on a Linux machine.

View 2 Replies View Related

C :: How To Apply Mutex Lock On Shared Memory

Jul 11, 2014

I was trying to put mutex lock on shared memory but my code is not working. What I want is that if some process is putting something on shared memory segment, other process should not be able to access that segment. For testing , I create a server program which put data in shared memory and client program which access the data.

To test it, I put break point after:

pthread_mutex_lock(&(init_lock));

But I see that client program was able to access shared memory.

Below is code:

Server: Code: pthread_mutex_t init_lock = PTHREAD_MUTEX_INITIALIZER;
main()
{
char c;

[Code].....

View 1 Replies View Related

C/C++ :: Shared Memory Project Not Getting Accurate Count For Processes

Jan 30, 2014

I'm working on a project that is supposed to create 3 processes. Process 1 should count from 1 to 100,000. Process 2 from 1 to 200,000. Process 3 from 1 to 300,000. I've written the basic code of it but my processes aren't printing out very accurate numbers.

Here's my code:

/*ass1*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdlib.h>
#include <unistd.h>
/* change the key number */
#define SHMKEY ((key_t) 8450)
typedef struct

[code]....

View 4 Replies View Related

C/C++ :: Know That Data Written To Shared Memory Segment In Unix Is Stored Properly

Mar 8, 2012

I am trying to write a client/server application that takes input to an array of structures from the user,stores the data in a shared memory segment and then writes the same to a file when I close the application. How do I get started? And how do I ensure that the server stores the data correctly? Also, the server needs to be a concurrent server that accepts connections from multiple clients.

View 1 Replies View Related

C# :: Making Moving Button Or Moving Picture Box Clickable?

Jun 13, 2014

i want to make moving button or moving box clickable as i am making a game in which i move picture boxes and user clicks on it and his scores increases. but i was unable to do so , so i tried the same concept with buttons but no results.

View 7 Replies View Related

C++ :: How Class Objects Stored In Memory

Aug 23, 2014

For example when I have:

Class A{
B objectB;
};

Now when I instantiate the object of class A like:

main(){
A objectA;//option 1
A* pObjectA = new A();// option2
}

How is objectB stored in memory (stack heap etc.) for both options??

View 1 Replies View Related

C++ :: Shared Pointer Dropping?

Sep 19, 2014

Is their a way to completely drop a shared_ptr. Then it will delete the memory and NULL all pointers linking to it?

View 4 Replies View Related

C++ :: Multithreading - How To Modify Shared Object

Aug 24, 2014

class MyOwner {
...
int m_count;
bool b_locked;
};

[Code] ....

I am using an API where I create many MyObjects on the heap, and the API uses a separate thread to send messages to each object. Each MyObject contains a pointer to MyOwner.

Suppose I want to keep a count of all messages received in all MyObjects: How can I do this in a thread safe way?

I am assuming that the code I have written above will not be safe--at the very least it seems that it would potentially miss message counts when it was locked--not the worse case scenario for me. I am most concerned about not causing the application to crash.

View 5 Replies View Related

C++ :: Cannot Open Shared Object File

Nov 11, 2013

i'm writing a lexer, and i want to use boost::regex for it. im sure im using it right (just in case though)

while(!this->Source.empty())
{
if(regex_search(Start, End, Match, regex(""[^"]*""), Flags))

[code].....

someone told me to download the latest source and build that so i did, by unzipping it, cding to the source, running ./bootstrap.sh, ./b2, and finally ./b2 install. when i compile i get no errors but when i run it i get ./jade: error while loading shared libraries: libboost_regex.so.1.55.0: cannot open shared object file: No such file or directory

View 6 Replies View Related

C++ :: How To Create Pros And Cons Of Shared Libraries

Aug 18, 2014

I want to know:

1. Pros and cons of shared libraries
2. How to create them(any tutorial link or book will be good)
3. Compare static libraries to dynamic ones

View 1 Replies View Related

C++ :: Shared Library Throws Exception But Not Caught

Jan 10, 2013

A test program of mine loads a shared library (.so file). A function call in the shared library throws an exception that I am trying to catch in the main function of my test program. (I know that exception is being thrown for sure, I wrote the library to do that.)

However in the main program, the exception is not being caught. The flow of program goes past the catch block like no error has occurred. I am using g++ and I load the shared file using -l option. Only trying to load the program statically I got the following error:

/usr/bin/ld: cannot find -lmy-shared-library
collect2: ld returned 1 exit status

Why the exception is not getting caught.

View 9 Replies View Related

C++ :: Shared Library Export And Calling Convention?

Aug 13, 2013

I want to create a simple shared library that exports a simple C API, just like llvm-clang.

The library should be compilable with any compiler and be used by a variety of languages, again just like clang.

For visual studio that is:

Code:
extern "C" __declspec(dllexport) void __cdecl myfunc(int arg);

The __cdecl is the issue here: i cannot seem to find a compiler agnostic way of specifying the use of cdecl.

So i went to see how my favorite C API libraries (ie clang) handle it.

none of them specify a calling convention at all!

Code:
#define CINDEX_LINKAGE __declspec(dllexport)
CINDEX_LINKAGE void clang_disposeIndex(CXIndex index); //exported

how does that work? How does the compiler know to use __cdecl and how would i link to it dynamically without that knowledge?

View 1 Replies View Related

Visual C++ :: Command For List Out Shared Folder In MFC?

Apr 12, 2013

I need to list out all the shared folders(directory) in the system along with their path . i want a command or an api in MFC, for listing out the shared directories.

View 2 Replies View Related

C :: How To Create A Shared Library From Source Code In Autopy

Jan 22, 2013

I'm trying to find a C library for automating mouse clicks and keystrokes, something like the Python package AutoPy would be ideal.

Might have heard of Auto-it [URL] ...., which automates GUIs in Windows. Something like that would also be good, but my main OS is Linux.

I'm not sure whether it would be possible to create a shared library from the C source code in autopy.

View 4 Replies View Related

C++ :: Moving From One Coordinate To Another

Feb 18, 2015

I have a character at a co-ordinate, say (3,4) for example, and I need to get him to (10,15). I would like him to move one block every tick or half a second, so that you can see him moving towards his destination. How to achieve this?

View 3 Replies View Related

C++ :: Moving In A Circle

Apr 15, 2014

I'm making this program to mess with people and make them think its a virus.

#define _WIN32_WINNT 0x0500 //For hiding your console
#include <cstdlib>
#include <iostream>
#include <Windows.h>
#include <WinBase.h>

[Code]....

At line 42 and 43 I want to make the cursor move around in a circle over and over again but I'm not sure how.

View 4 Replies View Related

C++ :: Moving Object In Array

Nov 30, 2014

I want to make an object in array[][] move

Ex:
array[2][5]
array[0][0] = 'O'

O| | | | |
| | | | |
| | | | |

then
|O| | | |
| | | | |
| | | | |

then
| |O| | |
| | | | |
| | | | |

......

how can i print my array in console then change&print it again, then change&print it again,... So it look like O is moving
???

View 1 Replies View Related

C++ :: Moving Character Up / Down And Left / Right

Apr 28, 2013

I have a board where a character is. I need to ask the user whether they want to move it up, down, left right. They are allowed to enter 3 move per turn. like up, up, left. How do I do this?

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

const int COL = 17;
const int ROW = 17;

[Code] .....

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved