Set shared_ptr with new_pointer that is old_pointer + offset
Here is a smart pointer: std::shared_ptr<char> p(new char[size]) which represents array filled with raw binary file content. After (and only after) the whole array is copied from file to RAM, I can parse it, and during this I retrieve some header information (a few first dwords). Then actual data follows.
Without giving much more context, it's handy for me to to set mentioned shared pointer to new address that is beginning of actual data. This address is still in alocated memory. But how to set without losing it?
A question is (yes/no): Is it possible to set p to offset of prevous pointer, without invoking deletion of data?
c++ shared-ptr smart-pointers pointer-arithmetic
|
show 1 more comment
Here is a smart pointer: std::shared_ptr<char> p(new char[size]) which represents array filled with raw binary file content. After (and only after) the whole array is copied from file to RAM, I can parse it, and during this I retrieve some header information (a few first dwords). Then actual data follows.
Without giving much more context, it's handy for me to to set mentioned shared pointer to new address that is beginning of actual data. This address is still in alocated memory. But how to set without losing it?
A question is (yes/no): Is it possible to set p to offset of prevous pointer, without invoking deletion of data?
c++ shared-ptr smart-pointers pointer-arithmetic
3
Unfortunately, shared pointers don't work this way, and this cannot be done. You will need to find some other way to accomplish this goal. The short answer is: "no".
– Sam Varshavchik
Feb 17 at 20:50
5
This sounds like a case where you'd want to pass a raw pointer instead of ashared_ptr.
– Jeremy Friesner
Feb 17 at 20:55
^^^ that's what it seems. Or tote around a offset value and base your data-read fromp.get() + header_len. Trying to change the shared pointerpitself seems odd here.
– WhozCraig
Feb 17 at 20:57
@JeremyFriesner I know and I will handle this situation, because I coded this shared pointer myself and futhermore I can read from file and parse simultaneously (lied in question). Just was wondering are smart pointers that good for low-level binary work. Thanks for suggestion.
– Alex Larionov
Feb 17 at 21:00
Usevector<char>instead of a raw array.
– Ulrich Eckhardt
Feb 17 at 21:14
|
show 1 more comment
Here is a smart pointer: std::shared_ptr<char> p(new char[size]) which represents array filled with raw binary file content. After (and only after) the whole array is copied from file to RAM, I can parse it, and during this I retrieve some header information (a few first dwords). Then actual data follows.
Without giving much more context, it's handy for me to to set mentioned shared pointer to new address that is beginning of actual data. This address is still in alocated memory. But how to set without losing it?
A question is (yes/no): Is it possible to set p to offset of prevous pointer, without invoking deletion of data?
c++ shared-ptr smart-pointers pointer-arithmetic
Here is a smart pointer: std::shared_ptr<char> p(new char[size]) which represents array filled with raw binary file content. After (and only after) the whole array is copied from file to RAM, I can parse it, and during this I retrieve some header information (a few first dwords). Then actual data follows.
Without giving much more context, it's handy for me to to set mentioned shared pointer to new address that is beginning of actual data. This address is still in alocated memory. But how to set without losing it?
A question is (yes/no): Is it possible to set p to offset of prevous pointer, without invoking deletion of data?
c++ shared-ptr smart-pointers pointer-arithmetic
c++ shared-ptr smart-pointers pointer-arithmetic
edited Feb 17 at 21:40
Christophe
41.3k43678
41.3k43678
asked Feb 17 at 20:49
Alex LarionovAlex Larionov
24348
24348
3
Unfortunately, shared pointers don't work this way, and this cannot be done. You will need to find some other way to accomplish this goal. The short answer is: "no".
– Sam Varshavchik
Feb 17 at 20:50
5
This sounds like a case where you'd want to pass a raw pointer instead of ashared_ptr.
– Jeremy Friesner
Feb 17 at 20:55
^^^ that's what it seems. Or tote around a offset value and base your data-read fromp.get() + header_len. Trying to change the shared pointerpitself seems odd here.
– WhozCraig
Feb 17 at 20:57
@JeremyFriesner I know and I will handle this situation, because I coded this shared pointer myself and futhermore I can read from file and parse simultaneously (lied in question). Just was wondering are smart pointers that good for low-level binary work. Thanks for suggestion.
– Alex Larionov
Feb 17 at 21:00
Usevector<char>instead of a raw array.
– Ulrich Eckhardt
Feb 17 at 21:14
|
show 1 more comment
3
Unfortunately, shared pointers don't work this way, and this cannot be done. You will need to find some other way to accomplish this goal. The short answer is: "no".
– Sam Varshavchik
Feb 17 at 20:50
5
This sounds like a case where you'd want to pass a raw pointer instead of ashared_ptr.
– Jeremy Friesner
Feb 17 at 20:55
^^^ that's what it seems. Or tote around a offset value and base your data-read fromp.get() + header_len. Trying to change the shared pointerpitself seems odd here.
– WhozCraig
Feb 17 at 20:57
@JeremyFriesner I know and I will handle this situation, because I coded this shared pointer myself and futhermore I can read from file and parse simultaneously (lied in question). Just was wondering are smart pointers that good for low-level binary work. Thanks for suggestion.
– Alex Larionov
Feb 17 at 21:00
Usevector<char>instead of a raw array.
– Ulrich Eckhardt
Feb 17 at 21:14
3
3
Unfortunately, shared pointers don't work this way, and this cannot be done. You will need to find some other way to accomplish this goal. The short answer is: "no".
– Sam Varshavchik
Feb 17 at 20:50
Unfortunately, shared pointers don't work this way, and this cannot be done. You will need to find some other way to accomplish this goal. The short answer is: "no".
– Sam Varshavchik
Feb 17 at 20:50
5
5
This sounds like a case where you'd want to pass a raw pointer instead of a
shared_ptr.– Jeremy Friesner
Feb 17 at 20:55
This sounds like a case where you'd want to pass a raw pointer instead of a
shared_ptr.– Jeremy Friesner
Feb 17 at 20:55
^^^ that's what it seems. Or tote around a offset value and base your data-read from
p.get() + header_len. Trying to change the shared pointer p itself seems odd here.– WhozCraig
Feb 17 at 20:57
^^^ that's what it seems. Or tote around a offset value and base your data-read from
p.get() + header_len. Trying to change the shared pointer p itself seems odd here.– WhozCraig
Feb 17 at 20:57
@JeremyFriesner I know and I will handle this situation, because I coded this shared pointer myself and futhermore I can read from file and parse simultaneously (lied in question). Just was wondering are smart pointers that good for low-level binary work. Thanks for suggestion.
– Alex Larionov
Feb 17 at 21:00
@JeremyFriesner I know and I will handle this situation, because I coded this shared pointer myself and futhermore I can read from file and parse simultaneously (lied in question). Just was wondering are smart pointers that good for low-level binary work. Thanks for suggestion.
– Alex Larionov
Feb 17 at 21:00
Use
vector<char> instead of a raw array.– Ulrich Eckhardt
Feb 17 at 21:14
Use
vector<char> instead of a raw array.– Ulrich Eckhardt
Feb 17 at 21:14
|
show 1 more comment
1 Answer
1
active
oldest
votes
Yes this is possible. You can use constructor 8, the aliasing constructor from this reference: https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr
// make sure you use an array deleter
std::shared_ptr<char> osp(new char[1024], std::default_delete<char>());
// load the data into your buffer at osp.get()
// Find the offset in the data by parsing
auto const offset = parse_buffer_for_offset(osp.get());
// Now set a new offset into the data
std::shared_ptr<char> nsp(osp, osp.get() + offset);
Now nsp.get() returns the offset address but the original array will get deleted properly.
Note: The offset is a property of each shared_ptr so if you copy the shared_ptr nsp you get another shared_ptr with the same offset. This works whether you construct a new copy or assign a copy to an existing shared_ptr.
This means you can have different shared_ptr with different offsets that all manage the same, underlying resource which will only be cleaned up after all shared_ptr are destroyed.
To see this in operation consider the following code:
std::shared_ptr<char> original_sp(new char[1024], std::default_delete<char>());
std::shared_ptr<char> offset_100_sp1(original_sp, original_sp.get() + 100);
std::shared_ptr<char> offset_100_sp2 = offset_100_sp1;
std::shared_ptr<char> offset_200_sp1(original_sp, original_sp.get() + 200);
std::shared_ptr<char> offset_200_sp2 = offset_200_sp1;
std::cout << "nPointers managing the array: " << original_sp.use_count() << 'n';
std::cout << "nOffset 100 pointers:" << 'n';
std::cout << std::distance(original_sp.get(), offset_100_sp1.get()) << 'n';
std::cout << std::distance(original_sp.get(), offset_100_sp2.get()) << 'n';
std::cout << "nOffset 200 pointers:" << 'n';
std::cout << std::distance(original_sp.get(), offset_200_sp1.get()) << 'n';
std::cout << std::distance(original_sp.get(), offset_200_sp2.get()) << 'n';
Output:
Pointers managing the array: 5
Offset 100 pointers:
100
100
Offset 200 pointers:
200
200
3
Yes this is exactly what the aliasing constructor is for!
– n.m.
Feb 17 at 21:12
Of course, while this shares ownership with theshared_ptrused during creation (and all its clones), the offset is not applied to any of the existing clones. So it's not clear to meet whether this meets the question's stated goal of "setting" the shared_ptr
– Ben Voigt
Feb 18 at 4:09
@BenVoigt I have made a note to the effect that the offset belongs to eachshared_ptrand that offsets are transferred to anothershared_ptrwhen copied (either copy constructed or copy assigned).
– Galik
Feb 18 at 4:48
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54737556%2fset-shared-ptr-with-new-pointer-that-is-old-pointer-offset%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Yes this is possible. You can use constructor 8, the aliasing constructor from this reference: https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr
// make sure you use an array deleter
std::shared_ptr<char> osp(new char[1024], std::default_delete<char>());
// load the data into your buffer at osp.get()
// Find the offset in the data by parsing
auto const offset = parse_buffer_for_offset(osp.get());
// Now set a new offset into the data
std::shared_ptr<char> nsp(osp, osp.get() + offset);
Now nsp.get() returns the offset address but the original array will get deleted properly.
Note: The offset is a property of each shared_ptr so if you copy the shared_ptr nsp you get another shared_ptr with the same offset. This works whether you construct a new copy or assign a copy to an existing shared_ptr.
This means you can have different shared_ptr with different offsets that all manage the same, underlying resource which will only be cleaned up after all shared_ptr are destroyed.
To see this in operation consider the following code:
std::shared_ptr<char> original_sp(new char[1024], std::default_delete<char>());
std::shared_ptr<char> offset_100_sp1(original_sp, original_sp.get() + 100);
std::shared_ptr<char> offset_100_sp2 = offset_100_sp1;
std::shared_ptr<char> offset_200_sp1(original_sp, original_sp.get() + 200);
std::shared_ptr<char> offset_200_sp2 = offset_200_sp1;
std::cout << "nPointers managing the array: " << original_sp.use_count() << 'n';
std::cout << "nOffset 100 pointers:" << 'n';
std::cout << std::distance(original_sp.get(), offset_100_sp1.get()) << 'n';
std::cout << std::distance(original_sp.get(), offset_100_sp2.get()) << 'n';
std::cout << "nOffset 200 pointers:" << 'n';
std::cout << std::distance(original_sp.get(), offset_200_sp1.get()) << 'n';
std::cout << std::distance(original_sp.get(), offset_200_sp2.get()) << 'n';
Output:
Pointers managing the array: 5
Offset 100 pointers:
100
100
Offset 200 pointers:
200
200
3
Yes this is exactly what the aliasing constructor is for!
– n.m.
Feb 17 at 21:12
Of course, while this shares ownership with theshared_ptrused during creation (and all its clones), the offset is not applied to any of the existing clones. So it's not clear to meet whether this meets the question's stated goal of "setting" the shared_ptr
– Ben Voigt
Feb 18 at 4:09
@BenVoigt I have made a note to the effect that the offset belongs to eachshared_ptrand that offsets are transferred to anothershared_ptrwhen copied (either copy constructed or copy assigned).
– Galik
Feb 18 at 4:48
add a comment |
Yes this is possible. You can use constructor 8, the aliasing constructor from this reference: https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr
// make sure you use an array deleter
std::shared_ptr<char> osp(new char[1024], std::default_delete<char>());
// load the data into your buffer at osp.get()
// Find the offset in the data by parsing
auto const offset = parse_buffer_for_offset(osp.get());
// Now set a new offset into the data
std::shared_ptr<char> nsp(osp, osp.get() + offset);
Now nsp.get() returns the offset address but the original array will get deleted properly.
Note: The offset is a property of each shared_ptr so if you copy the shared_ptr nsp you get another shared_ptr with the same offset. This works whether you construct a new copy or assign a copy to an existing shared_ptr.
This means you can have different shared_ptr with different offsets that all manage the same, underlying resource which will only be cleaned up after all shared_ptr are destroyed.
To see this in operation consider the following code:
std::shared_ptr<char> original_sp(new char[1024], std::default_delete<char>());
std::shared_ptr<char> offset_100_sp1(original_sp, original_sp.get() + 100);
std::shared_ptr<char> offset_100_sp2 = offset_100_sp1;
std::shared_ptr<char> offset_200_sp1(original_sp, original_sp.get() + 200);
std::shared_ptr<char> offset_200_sp2 = offset_200_sp1;
std::cout << "nPointers managing the array: " << original_sp.use_count() << 'n';
std::cout << "nOffset 100 pointers:" << 'n';
std::cout << std::distance(original_sp.get(), offset_100_sp1.get()) << 'n';
std::cout << std::distance(original_sp.get(), offset_100_sp2.get()) << 'n';
std::cout << "nOffset 200 pointers:" << 'n';
std::cout << std::distance(original_sp.get(), offset_200_sp1.get()) << 'n';
std::cout << std::distance(original_sp.get(), offset_200_sp2.get()) << 'n';
Output:
Pointers managing the array: 5
Offset 100 pointers:
100
100
Offset 200 pointers:
200
200
3
Yes this is exactly what the aliasing constructor is for!
– n.m.
Feb 17 at 21:12
Of course, while this shares ownership with theshared_ptrused during creation (and all its clones), the offset is not applied to any of the existing clones. So it's not clear to meet whether this meets the question's stated goal of "setting" the shared_ptr
– Ben Voigt
Feb 18 at 4:09
@BenVoigt I have made a note to the effect that the offset belongs to eachshared_ptrand that offsets are transferred to anothershared_ptrwhen copied (either copy constructed or copy assigned).
– Galik
Feb 18 at 4:48
add a comment |
Yes this is possible. You can use constructor 8, the aliasing constructor from this reference: https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr
// make sure you use an array deleter
std::shared_ptr<char> osp(new char[1024], std::default_delete<char>());
// load the data into your buffer at osp.get()
// Find the offset in the data by parsing
auto const offset = parse_buffer_for_offset(osp.get());
// Now set a new offset into the data
std::shared_ptr<char> nsp(osp, osp.get() + offset);
Now nsp.get() returns the offset address but the original array will get deleted properly.
Note: The offset is a property of each shared_ptr so if you copy the shared_ptr nsp you get another shared_ptr with the same offset. This works whether you construct a new copy or assign a copy to an existing shared_ptr.
This means you can have different shared_ptr with different offsets that all manage the same, underlying resource which will only be cleaned up after all shared_ptr are destroyed.
To see this in operation consider the following code:
std::shared_ptr<char> original_sp(new char[1024], std::default_delete<char>());
std::shared_ptr<char> offset_100_sp1(original_sp, original_sp.get() + 100);
std::shared_ptr<char> offset_100_sp2 = offset_100_sp1;
std::shared_ptr<char> offset_200_sp1(original_sp, original_sp.get() + 200);
std::shared_ptr<char> offset_200_sp2 = offset_200_sp1;
std::cout << "nPointers managing the array: " << original_sp.use_count() << 'n';
std::cout << "nOffset 100 pointers:" << 'n';
std::cout << std::distance(original_sp.get(), offset_100_sp1.get()) << 'n';
std::cout << std::distance(original_sp.get(), offset_100_sp2.get()) << 'n';
std::cout << "nOffset 200 pointers:" << 'n';
std::cout << std::distance(original_sp.get(), offset_200_sp1.get()) << 'n';
std::cout << std::distance(original_sp.get(), offset_200_sp2.get()) << 'n';
Output:
Pointers managing the array: 5
Offset 100 pointers:
100
100
Offset 200 pointers:
200
200
Yes this is possible. You can use constructor 8, the aliasing constructor from this reference: https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr
// make sure you use an array deleter
std::shared_ptr<char> osp(new char[1024], std::default_delete<char>());
// load the data into your buffer at osp.get()
// Find the offset in the data by parsing
auto const offset = parse_buffer_for_offset(osp.get());
// Now set a new offset into the data
std::shared_ptr<char> nsp(osp, osp.get() + offset);
Now nsp.get() returns the offset address but the original array will get deleted properly.
Note: The offset is a property of each shared_ptr so if you copy the shared_ptr nsp you get another shared_ptr with the same offset. This works whether you construct a new copy or assign a copy to an existing shared_ptr.
This means you can have different shared_ptr with different offsets that all manage the same, underlying resource which will only be cleaned up after all shared_ptr are destroyed.
To see this in operation consider the following code:
std::shared_ptr<char> original_sp(new char[1024], std::default_delete<char>());
std::shared_ptr<char> offset_100_sp1(original_sp, original_sp.get() + 100);
std::shared_ptr<char> offset_100_sp2 = offset_100_sp1;
std::shared_ptr<char> offset_200_sp1(original_sp, original_sp.get() + 200);
std::shared_ptr<char> offset_200_sp2 = offset_200_sp1;
std::cout << "nPointers managing the array: " << original_sp.use_count() << 'n';
std::cout << "nOffset 100 pointers:" << 'n';
std::cout << std::distance(original_sp.get(), offset_100_sp1.get()) << 'n';
std::cout << std::distance(original_sp.get(), offset_100_sp2.get()) << 'n';
std::cout << "nOffset 200 pointers:" << 'n';
std::cout << std::distance(original_sp.get(), offset_200_sp1.get()) << 'n';
std::cout << std::distance(original_sp.get(), offset_200_sp2.get()) << 'n';
Output:
Pointers managing the array: 5
Offset 100 pointers:
100
100
Offset 200 pointers:
200
200
edited Feb 18 at 5:14
answered Feb 17 at 21:07
GalikGalik
34.7k35281
34.7k35281
3
Yes this is exactly what the aliasing constructor is for!
– n.m.
Feb 17 at 21:12
Of course, while this shares ownership with theshared_ptrused during creation (and all its clones), the offset is not applied to any of the existing clones. So it's not clear to meet whether this meets the question's stated goal of "setting" the shared_ptr
– Ben Voigt
Feb 18 at 4:09
@BenVoigt I have made a note to the effect that the offset belongs to eachshared_ptrand that offsets are transferred to anothershared_ptrwhen copied (either copy constructed or copy assigned).
– Galik
Feb 18 at 4:48
add a comment |
3
Yes this is exactly what the aliasing constructor is for!
– n.m.
Feb 17 at 21:12
Of course, while this shares ownership with theshared_ptrused during creation (and all its clones), the offset is not applied to any of the existing clones. So it's not clear to meet whether this meets the question's stated goal of "setting" the shared_ptr
– Ben Voigt
Feb 18 at 4:09
@BenVoigt I have made a note to the effect that the offset belongs to eachshared_ptrand that offsets are transferred to anothershared_ptrwhen copied (either copy constructed or copy assigned).
– Galik
Feb 18 at 4:48
3
3
Yes this is exactly what the aliasing constructor is for!
– n.m.
Feb 17 at 21:12
Yes this is exactly what the aliasing constructor is for!
– n.m.
Feb 17 at 21:12
Of course, while this shares ownership with the
shared_ptr used during creation (and all its clones), the offset is not applied to any of the existing clones. So it's not clear to meet whether this meets the question's stated goal of "setting" the shared_ptr– Ben Voigt
Feb 18 at 4:09
Of course, while this shares ownership with the
shared_ptr used during creation (and all its clones), the offset is not applied to any of the existing clones. So it's not clear to meet whether this meets the question's stated goal of "setting" the shared_ptr– Ben Voigt
Feb 18 at 4:09
@BenVoigt I have made a note to the effect that the offset belongs to each
shared_ptr and that offsets are transferred to another shared_ptr when copied (either copy constructed or copy assigned).– Galik
Feb 18 at 4:48
@BenVoigt I have made a note to the effect that the offset belongs to each
shared_ptr and that offsets are transferred to another shared_ptr when copied (either copy constructed or copy assigned).– Galik
Feb 18 at 4:48
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54737556%2fset-shared-ptr-with-new-pointer-that-is-old-pointer-offset%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Unfortunately, shared pointers don't work this way, and this cannot be done. You will need to find some other way to accomplish this goal. The short answer is: "no".
– Sam Varshavchik
Feb 17 at 20:50
5
This sounds like a case where you'd want to pass a raw pointer instead of a
shared_ptr.– Jeremy Friesner
Feb 17 at 20:55
^^^ that's what it seems. Or tote around a offset value and base your data-read from
p.get() + header_len. Trying to change the shared pointerpitself seems odd here.– WhozCraig
Feb 17 at 20:57
@JeremyFriesner I know and I will handle this situation, because I coded this shared pointer myself and futhermore I can read from file and parse simultaneously (lied in question). Just was wondering are smart pointers that good for low-level binary work. Thanks for suggestion.
– Alex Larionov
Feb 17 at 21:00
Use
vector<char>instead of a raw array.– Ulrich Eckhardt
Feb 17 at 21:14