# How do I create a CPU read/write buffer in SlimDX (what are the legal combinations of Usage and CPUAccess flags)?

Currently, I create a vertex buffer in SlimDX like so:

SlimDX.Direct3D11.BufferDescription Description = new SlimDX.Direct3D11.BufferDescription();

Description.BindFlags = SlimDX.Direct3D11.BindFlags.VertexBuffer;
Description.CpuAccessFlags = SlimDX.Direct3D11.CpuAccessFlags.Write;
Description.OptionFlags = SlimDX.Direct3D11.ResourceOptionFlags.None;
Description.SizeInBytes = _BufferSize;
Description.StructureByteStride = 0;
Description.Usage = SlimDX.Direct3D11.ResourceUsage.Dynamic;

_Buffer = new SlimDX.Direct3D11.Buffer(Parent.Device, Description);


Which I can update:

DataBox box = _Parent.Context.MapSubresource(_Buffer, 0, _BufferSize, SlimDX.Direct3D11.MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None);
box.Data.Position = destStartPosition * _VertexStride;
/* Where T is my vertex structure type */
box.Data.WriteRange<T>(data);
_Parent.Context.UnmapSubresource(_Buffer, 0);


My first question is about the MapSubresource parameter MapMode.WriteDiscard: when the documentation says

"the previous contents of the resource will be undefined"

, does that mean that if I only update part of the buffer, when it is unmapped the remainder could become anything? Or simply that if I read from the DataStream there is no guarantee what I am reading will be valid?

Second, if I specify MapMode.Write, SlimDX will throw an exception (E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)). Why is this? The documentation says that I only need to have a writeable buffer for this to be valid, which I do, because that is the same requirement for WriteDiscard which I can pass successfully.

One last question, if I specify:

Description.CpuAccessFlags = (SlimDX.Direct3D11.CpuAccessFlags.Write | SlimDX.Direct3D11.CpuAccessFlags.Read);
Description.Usage = (SlimDX.Direct3D11.ResourceUsage.Dynamic | SlimDX.Direct3D11.ResourceUsage.Staging);


The same exception is thrown, but this is the only combination of flags I can see that would give me a ReadWrite buffer, how can I create one?