maybe a dumb question

This is a discussion on maybe a dumb question within the C++ Programming forums, part of the General Programming Boards category; I could just try it, but now I figure asking is alot quicker. Can you pass pointers to other programs? ...

  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,678

    maybe a dumb question

    I could just try it, but now I figure asking is alot quicker.
    Can you pass pointers to other programs? (not handles or anything, I mean pointers made with new or malloc.)
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Sure

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You can pass them, sure - they're just numbers. But you can't use them there, because the other program uses a different address space, so the pointer would be meaningless.

    The exception are function pointers to functions in DLLs, which may point to the same function, provided that the DLL is present in both apps and mapped to the same base address.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    If you allocate data in shared memory, multiple processes should be able to access it.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,899
    I could add that it is possible to share memory between processes using some type of shared memory such as memory mapped files, but it's not possible to pass a pointer directly and expect the other process to be able to use the memory in another process. It doesn't work that way due to virtual memory.
    Of course, you could also read other processes' memory using special API, but I don't think it's really recommended for purpose such as this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,678
    Okay, now I know.

    Do you know of an easy way to create shared memory?
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,899
    Memory Mapped files. There is a very nice sample code at CodeProject. It's called CMemMapFile. Very handy and easy to use class. Search for it!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,678
    found it. Nice.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  9. #9
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    or in UNIX there's a bunch of functions that start with "shm", like shmat(), shmdt(), shmget(), shmctl()...

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The file-based shared memory do not allow any specification of the base-address of the mapping, it will be allocated as the OS sees fit. So pointers in the first process are not pointing to the same thing in the second process.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    There's also Boost.Interprocess. It will be part of the upcoming 1.35 release. Aside from raw shared memory and memory-mapped files, Interprocess also provides special containers that can reside in such memory.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dumb question
    By travis999 in forum C Programming
    Replies: 3
    Last Post: 10-26-2007, 01:57 AM
  2. very dumb question.
    By Blips in forum C++ Programming
    Replies: 14
    Last Post: 11-08-2005, 09:37 AM
  3. Dumb question
    By dragon2309 in forum C Programming
    Replies: 18
    Last Post: 10-29-2005, 04:27 PM
  4. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  5. another dumb question - loop not working?
    By Captain Penguin in forum C++ Programming
    Replies: 8
    Last Post: 10-06-2002, 11:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21