Like @dhruvgovil said, in our (and most external users, it seems?) workflows, the ability to create, write-to, and “Export” an in-memory (called “anonymous”) layer has covered most bases since the creation of Presto twenty+ years ago.
Firstly, what you need to do if you want to pursue this (and then why) : The missing piece is a custom “URI” ArResolver which, given an identifier (which it gets from SdfLayer::CreateNew()), will create the ArInMemoryAsset you need and attach it to a concrete Layer (more specifically, the underlying instance of an SdfAbstractData container associated with the SdfFIleFormat you have indicated in the extension of the identifier). So, if you choose a URI class/protocol like “inmem”, then you could create layers like SdfLayer::CreateNew("inmem:aBufferLayer.usdc")
OK, that’s a little misleading, because that’s the simpler "Creating a new empty layer that you could then use the normal SdfLayer API’s to populate, and the resolver would actually be creating an ArWritableAsset. But your use case, I believe, is to create a Layer for reading, from a sequential buffer you already have in memory. For that to work, you need to encode in the identifier (or supply via SdfFileFormatArguments in your calls to SdfLayer::FindOrOpen()) enough information so that your resolver can find the buffer and use it as the source for the ArInMemoryAsset it creates. The simple, non-robust way to do that would be to encode a pointer as text. Blech. Better would be to add public API to your resolver that is available to your application where it can register buffers (maybe as unique_ptr’s?) associated with identifiers, so that when SdfLayer comes calling, it can find the appropriate buffer, and this also gives the resolver an opportunity to manage those buffers.
And now we get to why we’re putting you through all that rigamarole… SdfLayer actually has a number of facilities and public API that allow reasoning (timestamps, updating identifiers, determining if backing asset has changed and/or needs to be reloaded, etc) that fall into the category of “asset management”. All of that is mediated through the ArResolver abstraction, which is why we force you to go through that abstraction if you want to introduce any new kind of datasource - unless you’re willing to create a complete new FileFormat, which I think goes counter to your needs.
Dhruv mentioned InMemory/Anonymous layers as an existing mechanism that is “close”, and that does not require its own ArResolver. My answer is: it should!. But anonymous layers were deployed twenty years ago long before USD was a twinkle, and if you look at sdf/layer.cpp, you’ll see there a special cases for them polluting the code in numerous places. I think if we had the new “Ar 2.0” interface (designed and deployed around seven years ago to address community needs like URI resolvers and varied asset datasources) in place, then we would have worked hard to deploy anonymous layers as an “anon:” URI resolver, with maybe just the lightest sugar remaining for convenience, like SdfLayer::CreateAnonymous that simply prepends the URI class to the provided identifier.
I may have fudged some details in there, corrections welcome, and let us know if you have any further questions.