Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Is there a non-allocating String similar to a string_view in NTL?
Is there a non-allocating String similar to a string_view in NTL? [message #58462] Sat, 28 May 2022 08:37 Go to next message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 219
Registered: June 2011
Experienced Member
I have a COW database that uses mmap and the String type seems to either allocate or move when I would like to just have a const pointer/len to memory itself. Is there anything in NTL that can do this?
Re: Is there a non-allocating String similar to a string_view in NTL? [message #58463 is a reply to message #58462] Sat, 28 May 2022 08:41 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Quote:
I have a COW database that uses mmap and the String type seems to either allocate or move when I would like to just have a const pointer/len to memory itself. Is there anything in NTL that can do this?


How about Upp::MemReadStream? If I understand you correctly, this seems to be what you need.

Best regards,

Oblivion


Re: Is there a non-allocating String similar to a string_view in NTL? [message #58464 is a reply to message #58463] Sat, 28 May 2022 09:07 Go to previous messageGo to next message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 219
Registered: June 2011
Experienced Member
Oblivion wrote on Sat, 28 May 2022 08:41
Quote:
I have a COW database that uses mmap and the String type seems to either allocate or move when I would like to just have a const pointer/len to memory itself. Is there anything in NTL that can do this?


How about Upp::MemReadStream? If I understand you correctly, this seems to be what you need.

Best regards,

Oblivion


Nice. How would that work though for deserialization without copy?

I try:

#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN {
    const char *test = "this is a test";
    MemReadStream ms(test, strlen(test));
    
    String test2;
    ms % test2;
    
    Cout() << test2;
}


And the result is empty. GetLine returns a new String, Put(Cout()) is also empty.
Re: Is there a non-allocating String similar to a string_view in NTL? [message #58465 is a reply to message #58464] Sat, 28 May 2022 09:32 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Do you really need intermeadiary level?

    const char *test = "this is a test \n";
    MemReadStream ms(test, strlen(test));
    Cout().Put(ms); //cheap... 


(De)serialization, which eventually involves copying if you're going to put the data into new String, can be done via Stream helpers.(Eg LoadStream, SaveStream et al.)

Best regards,
Oblivion


[Updated on: Sat, 28 May 2022 09:34]

Report message to a moderator

Re: Is there a non-allocating String similar to a string_view in NTL? [message #58466 is a reply to message #58465] Sat, 28 May 2022 09:48 Go to previous message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 219
Registered: June 2011
Experienced Member
Oblivion wrote on Sat, 28 May 2022 09:32
Do you really need intermeadiary level?

    const char *test = "this is a test \n";
    MemReadStream ms(test, strlen(test));
    Cout().Put(ms); //cheap... 


(De)serialization, which eventually involves copying if you're going to put the data into new String, can be done via Stream helpers.(Eg LoadStream, SaveStream et al.)

Best regards,
Oblivion


Cool that works. ms.Put(Cout()) did not work.

Quote:

Do you really need intermeadiary level?


If it was just for display I'd be fine with copying, but suppose you wanted to perform a text search within the fields of a million mmaped records. It's a lot of unnecessary copying.
Previous Topic: Relocated Upp Folder - Missing Packages
Next Topic: No mouse hover tip?
Goto Forum:
  


Current Time: Thu Mar 28 10:48:09 CET 2024

Total time taken to generate the page: 0.01078 seconds