GithubHelp home page GithubHelp logo

mmap's Introduction

mmap Build Status Go Report Card MIT license PkgGoDev codecov

Interface for mmap syscall to provide safe and efficient access to memory. *mmap.File satisfies both io.ReaderAt and io.WriterAt interfaces.

Only works for darwin OS, Linux and Little Endian 64 bit architectures.

Safety & Efficiency

Golang mmap syscall function exposes the mapped memory as array of bytes. If the array is referenced even after the memory region is unmapped, this can lead to segmentation fault. mmap package provides safe access to the array of bytes by providing ReadAt and WriteAt functions.

WriteAt function copies a slice into the memory mapped region whereas ReadAt function copies data from memory mapped region to a given slice, therefore, avoiding exposing the array of bytes referring to mapped memory. This also avoids any extra data copy providing efficient access to the memory mapped region.

We have also added functions such as WriteUint64At, ReadUint64At that can directly typecast the mmaped memory to Uint64 and avoids an extra copy. We will add more functions in the library based on our use cases. If you need support for a particular function, let us know or better, raise a pull request.

Similar Packages

  • golang.org/x/exp/mmap
  • github.com/riobard/go-mmap
  • launchpad.net/gommap
  • github.com/edsrzf/mmap-go

mmap's People

Contributors

ashish-goswami avatar mangalaman93 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mmap's Issues

when i use `Flush` function not works on Linux(Ubuntu)

@mangalaman93 @ashish-goswami

hi, it's a nice package.
when i use Flush function works on Mac OS X ,but not work on Linux(Ubuntu). it will report the error : invalid argument

	err:=m.Flush(syscall.SYS_SYNC)
	if err!=nil {  
		t.Error(err) // L90
	}

error detail

FAIL: TestReadWrite (0.00s)
   mmap_test.go:90: invalid argument
FAIL
exit status 1
FAIL	github.com/grandecola/mmap	0.003s

Cloud you give me some advices? thanks ;)

Support various io.* interfaces

We should support interfaces in io package. To start with io.ReaderAt interface has very similar signature. There may be more such interfaces that type Mmap/IMmap could implement.

Take parsing functions as parameters to avoid need to change library

Currently we have two functions (ReadUint64 and WriteUint64) that are available to convert array of bytes into Uint64. Adding more function requires changes in the library in case of a need of different and more customized conversions.

Given that we do not want to expose the mmaped slice outside the library, this can be solved by taking conversion functions as arguments. This can clearly scope the mmaped array within the library itself.

For examples, consider following piece of code -

type RUint64 func([]byte) (uint64, error)
type WUint64 func([]byte, uint64) error

func (m *Mmap) ReadUint64(offset int, f RUint64) (uint64, error) {
        return f(m.data[offset : offset+8])
}

func (m *Mmap) WriteUint64(offset int, num uint64, f WUint64) {
	return f(m.data[offset:offset+8], num)
}

This is still not extensible to new types without changes to the library though provides customized conversion (such as for little endian architecture, big endian architecture). We can also provide default implementation for these types for direct usability.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.