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 8125595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:52:13+00:00 2026-06-06T06:52:13+00:00

Exposing STL containers over DLL boundaries is not a good idea, and generally not

  • 0

Exposing STL containers over DLL boundaries is not a good idea, and generally not possible (see this answer for why, and this one about exposing a std::list over a dll boundary). I need to be able to pass data between DLL and EXE compiled with different (VC08/VC10+) compilers; this Q only deals with everything being the same.

What is the best way to expose them? Vectors are a bit different from lists in that the memory is guaranteed to be contiguous, so if I only need a const vector of doubles, can I merely supply begin and end pointers to the block to the function in the dll? The dll also needs to return some structure like an array of vectors.

I wondered about a struct containing begin and end pointers:

template <typename T>
struct vecWrapper<T> {
    T*  begin;
    T*  end;
}

// in the dll
int func(vecWrapper<double> numbers);

Would that be sensible? Presumably whatever is returned from the function would need a destructor (on the dll side) that destroys the things it points to.

  • 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-06T06:52:14+00:00Added an answer on June 6, 2026 at 6:52 am

    You’ve pretty much nailed it. The standard requires vector elements to be contiguous in memory, and the vector elements won’t be stack-allocated unless you’re playing games with the vector’s allocator, so it’s always possible to represent the vector’s data as a start and end pointer (or a start pointer and a size, if that’s your thing). What you have should work fine.

    However, I’m not sure how much use that is. std::vector doesn’t really offer you anything except automatic memory management, and you don’t want that; otherwise any vectors you construct in the DLL will, when destructed, deallocate your original array of doubles. You can get around that by copying the array, but you’ve said you don’t want to do that either. STL algorithms work fine on pointers, so maybe there’s no need to convert in the DLL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why would you use one over the other, for exposing an API for your
When exposing some code to D-Bus using Qt D-Bus bindings, when should one use
I'm interested in one WCF server exposing both HTTP and TCP interfaces. It'll be
I have a wcf service thats exposing a service using two endpoints. One endpoint
I'm not looking for help on exposing virtual functions to Python, I would like
When performing a delete of a one-many relationship without exposing the foreign key, EF
What are the framework design guidelines for exposing a custom collection vs generic one?
On one Side I have Django exposing a SOAP entry point: soaplib 1.0 soaplib_handler.py
Ive been reading on some best practices for exposing Data over WCF Web Api
Given that directly exposing linq to sql or entity framework classes over web services

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.