Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8957023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:53:42+00:00 2026-06-15T14:53:42+00:00

At-most-once: A pointer to any specific object can exist in at most one container

  • 0

At-most-once: A pointer to any specific object can exist in at most one container object at any point in time.

Existence: An object must be dynamically allocated before a pointer to it is inserted.

Ownership: Once a pointer to an object is inserted, that objects becomes property of the container. No one else may use or modify it in any way.

Conservation: When a pointer is removed from a container, either the pointer must be inserted into some container, or its referent must be deleted.

These are the respective definitions I’ve been given. I’m having trouble understanding the various terminology used in each of them, and I was hoping someone here could explain exactly what each one means and how they’re used to ensure good programming practice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:53:43+00:00Added an answer on June 15, 2026 at 2:53 pm

    As an example, assume you have the following class definitions:

    class Container {
      public:
        // construct a container instance by making it point to an item
        Container(Item *pItem) : m_pItem(pItem) { }
      private:
        Item *m_pItem;
    };
    
    class Item {
      public:
        change() {
          // do something to change the item
        }
      private:
        // some private data
    };
    

    At-most-once: A pointer to any specific object can exist in at most one container object at any point in time.

    Having two instances of Container with a pointer to the same instance of Item would violate this:

    Item *pItem = new Item();  // construct a new Item
    Container c1(pItem);       // create a new container pointing to this item
    Container c2(pItem);       // WRONG: create another container pointing to the same item
    

    Existence: An object must be dynamically allocated before a pointer to it is inserted.

    Dynamically allocating an object generally means creating a new instance of an object with the operator new, which returns a pointer to the newly created object allocated on heap memory (as opposed to stack). Two examples of a violation of this are:

    Item *pItem = NULL;
    Container c1(pItem);  // WRONG: pItem is not dynamically allocated; it is NULL
    
    Item item;
    Container c2(&item);  // WRONG: &item does not point to a dynamically allocated heap
                          // object; the object is on stack;
    

    Ownership: Once a pointer to an object is inserted, that objects becomes property of the container. No one else may use or modify it in any way.

    When an object exists in memory, any object or function that has a pointer or reference to the object could potentially modify it (unless the pointer or reference is declared const):

    Item *pItem = new Item();  // the function containing this code obviously has a pointer
                               // to the newly created item
    Container c(pItem);        // let the container c own this item
    
    pItem->change();         // WRONG: attempt to modify an object owned by c
    

    Conservation: When a pointer is removed from a container, either the pointer must be inserted into some container, or its referent must be deleted.

    This means that when the container no longer wants to “own” (defined in exactly the same sense as above) the item instance it points to, it must either transfer “ownership” to another container, or delete the item. The following modification to the Container class implements this behavior:

    class Container {
      public:
        removeItem() {
          delete m_pItem;  // deallocate the item instance owned by this container
                           // the item is no longer owned because it no longer exists
        }
        giveItemTo(const Container& other) {
          other.m_pItem = m_pItem;  // let the other container own this item instead
          m_pItem = NULL;           // the item is no longer owned by this container because the pointer is NULL
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Memory allocation is one of the most time consuming operations in a GPU so
Most of you certainly use some kind of bugtracker. Maybe internally only, once a
Most things are dynamic in SSRS i.e you can create a custom expression for
Most objects in SAP ERP can be double clicked to get more information in
Most of the time, when designing an desktop application, I love to make the
I'm currently designing a object structure for a game, and the most natural organization
I want to check a string that contains the period, ., at most once
I was going through the rpc semantics, at-least-once and at-most-once semantics, how does they
I need to get the front-most address of a complete object even if what
Most of my user stories end up with tasks for create code review, carry

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.